• 一个activity


    package com.example.administrator.Activity;

    import android.content.Context;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.graphics.Bitmap;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.util.DisplayMetrics;
    import android.view.KeyEvent;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageButton;
    import android.widget.RelativeLayout;
    import android.widget.TextView;

    import com.example.administrator.Service.ADJFService;

    import org.json.JSONArray;
    import org.json.JSONObject;

    /**
    * Created by Administrator on 2016/1/19.
    */
    public class ADJFActivity extends AppCompatActivity {
    Toolbar ADJFToolBar;
    Intent intent;
    SharedPreferences ServicePointId;
    ADJFService adjfService;
    JSONArray adjfArray;
    Button ADJFBackButton;
    ImageButton ImageButtonAJJF,ImageButtonADJF,ImageButtonLJXD;
    TextView TextViewXD,TextViewZD,TextViewCDD,TextViewDD;
    RelativeLayout ADJFRelativeLayout;

    protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_adjf);
    InitRelativeLayout();
    InitToolBar();
    GetTextView();

    }
    private void InitRelativeLayout(){
    ADJFRelativeLayout = (RelativeLayout)findViewById(R.id.ADJFRelativeLayout);
    Drawable backgroud = getResources().getDrawable(R.drawable.adjfbackground);
    Bitmap bitmap ;
    }
    private void InitToolBar()
    {
    ADJFToolBar = (Toolbar) findViewById(R.id.ADJFToolBar);
    ADJFToolBar.setTitle("");
    setSupportActionBar(ADJFToolBar);
    ADJFBackButton = (Button) findViewById(R.id.ADJFBackButton);
    ADJFBackButton.setText("< 取消");
    ADJFBackButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    setResult(RESULT_OK, intent);
    finish();
    }
    });
    DisplayMetrics displaysMetrics = new DisplayMetrics();//获取屏幕分辨率
    ImageButtonAJJF = (ImageButton) findViewById(R.id.ADJFImageButtonAJJF);
    ImageButtonAJJF.setAdjustViewBounds(true);
    ImageButtonAJJF.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Intent intentADJF = new Intent();
    intentADJF.setClass(ADJFActivity.this, AJJFActivity.class);
    ADJFActivity.this.finish();
    startActivityForResult(intentADJF, 0);
    }
    });
    ImageButtonADJF = (ImageButton) findViewById(R.id.ADJFImageButtonADJF);
    ImageButtonADJF.setAdjustViewBounds(true);
    ImageButtonLJXD = (ImageButton) findViewById(R.id.ADJFImageButtonLJXD);
    ImageButtonLJXD.setAdjustViewBounds(true);
    getWindowManager().getDefaultDisplay().getMetrics(displaysMetrics);
    ImageButtonAJJF.setMaxWidth(displaysMetrics.widthPixels / 3);
    ImageButtonADJF.setMaxWidth(displaysMetrics.widthPixels / 3);
    ImageButtonLJXD.setMaxWidth(displaysMetrics.widthPixels-50);
    ImageButtonAJJF.getBackground().setAlpha(0);
    ImageButtonADJF.getBackground().setAlpha(0);
    ImageButtonLJXD.getBackground().setAlpha(0);
    ImageButtonLJXD.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Intent intentLJXD = new Intent();
    intentLJXD.setClass(ADJFActivity.this,OrderingActivity.class);
    ADJFActivity.this.finish();
    startActivityForResult(intentLJXD,0);
    }
    });
    }

    private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
    super.handleMessage(msg);
    InitTextView();
    }
    };
    private void GetTextView(){
    new Thread(new Runnable() {
    @Override
    public void run() {
    try {
    ServicePointId = getSharedPreferences("ServicePointId", Context.MODE_PRIVATE);
    String department = ServicePointId.getString("ServicePointId", null);
    adjfArray = adjfService.GetADJF(department);
    if (adjfArray != null) {
    handler.sendEmptyMessage(0);
    } else {
    return;
    }
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }).start();
    }
    private void InitTextView(){
    TextViewXD = (TextView)findViewById(R.id.TextViewCXD);
    JSONObject ajjfJSONObject1 = adjfArray.optJSONObject(0);
    String Price = ajjfJSONObject1.optString("price");
    TextViewXD.setText("¥" + Price + "/小袋");
    TextViewZD = (TextView)findViewById(R.id.TextViewZD);
    JSONObject ajjfJSONObject2 = adjfArray.optJSONObject(1);
    Price = ajjfJSONObject2.optString("price");
    TextViewZD.setText("¥"+Price+"/中袋");
    TextViewDD = (TextView)findViewById(R.id.TextViewDD);
    JSONObject ajjfJSONObject3 = adjfArray.optJSONObject(2);
    Price = ajjfJSONObject3.optString("price");
    TextViewDD.setText("¥"+Price+"/大袋");
    TextViewCDD = (TextView)findViewById(R.id.TextViewCDD);
    JSONObject ajjfJSONObject4 = adjfArray.optJSONObject(3);
    Price = ajjfJSONObject4.optString("price");
    TextViewCDD.setText("¥"+Price+"/超大袋");
    }
    }
  • 相关阅读:
    从Mono 4.0观C# 6.0部分新特性
    (译文)Python中的staticmethod与classmethod
    ubuntu中mysql中文乱码及用python3.x调用
    tornado学习 TCPClient 实现聊天功能
    tornado学习 TCPServer 实现聊天功能
    java基础知识3
    java基础知识5
    JSTL常用标签6
    Java基础知识2
    java基础知识4
  • 原文地址:https://www.cnblogs.com/to-creat/p/5678301.html
Copyright © 2020-2023  润新知