体温填报APP--主界面设计

主界面包括上述的功能选项

同时向用户提示你的当前用户信息

package com.example.tiwen20;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button shangbao_bt;
private Button qiehuan_bt;
private Button zhuce_bt;
private Button quanbutiwen_bt;
private Button shengchengbiao_bt;
private Button tongji_bt;
private Button MPandroid_bt,Map_bt,Map_bt1;
private Intent i,m,n,o,k,x,y,q,p;
private String name,classes;
private String str_location;
private Handler handler_location = new Handler();
private Toast toast;
private List<TiwenBean> list;
private TiwenDB tiwenDB;
private List<TiwenBean> listMPandroid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.activity_main);
initTiwen();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy( builder.build() );
}
}


private void initTiwen() {
shangbao_bt = (Button) this.findViewById(R.id.bt_shangbao);
qiehuan_bt = (Button) this.findViewById(R.id.bt_qiehuan);
zhuce_bt = (Button) this.findViewById(R.id.bt_zhuce);
quanbutiwen_bt = (Button) this.findViewById(R.id.bt_quanbutiwen);
shengchengbiao_bt = (Button) this.findViewById(R.id.bt_shengchengbiao);
tongji_bt = (Button) this.findViewById(R.id.bt_tongji);
MPandroid_bt = (Button) this.findViewById(R.id.bt_MPandroid);
Map_bt = (Button)this.findViewById(R.id.bt_Map);
Map_bt1 = (Button)this.findViewById(R.id.bt_Map1);
zhuce_bt.setOnClickListener(this);
shangbao_bt.setOnClickListener(this);
qiehuan_bt.setOnClickListener(this);
quanbutiwen_bt.setOnClickListener(this);
shengchengbiao_bt.setOnClickListener(this);
tongji_bt.setOnClickListener(this);
MPandroid_bt.setOnClickListener(this);
Map_bt.setOnClickListener(this);
Map_bt1.setOnClickListener(this);

}

public String getTime(){
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Date curDate = new Date();
String str = format.format(curDate);
return str;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_shangbao:
i = new Intent(this, addActivity.class);
i.putExtra("time",getTime());
i.putExtra("name",name);
LocationUtil locationUtil = new LocationUtil();
locationUtil.initLocation(getApplicationContext());
new Thread(new Runnable() {
@Override
public void run() {
try {
str_location= LocationUtil.getAddress(LocationUtil.location,getApplicationContext());
//位置信息-----一个字符串
}catch (IOException e){
e.printStackTrace();
}
final String finalStr_location = str_location;
handler_location.post(new Runnable() {
@Override
public void run() {
//Toast.makeText(getApplicationContext(), finalStr_location,Toast.LENGTH_LONG).show();
}
});
}
}).start();
i.putExtra("didian",str_location);
startActivity(i);
break;
case R.id.bt_zhuce:
m = new Intent(this, zhuceActivity.class);
startActivity(m);
break;
case R.id.bt_qiehuan:
k = new Intent(this,qiehuanActivity.class);
startActivity(k);
break;
case R.id.bt_quanbutiwen:
n = new Intent(this, alltiwenActivity.class);
startActivity(n);
break;
case R.id.bt_shengchengbiao:
x = new Intent(this,shengchengbiaoActivity.class);
x.putExtra("name",name);
startActivity(x);
break;
case R.id.bt_tongji:
o = new Intent(this,tongjiActivity.class);
o.putExtra("time",getTime());
o.putExtra("classes",classes);
startActivity(o);
break;
case R.id.bt_MPandroid:
y = new Intent(this,MPandroidActivity.class);
y.putExtra("name",name);
startActivity(y);
break;
case R.id.bt_Map:
q = new Intent(this,MapActivity.class);
q.putExtra("time",getTime());
q.putExtra("classes",classes);
startActivity(q);
break;
case R.id.bt_Map1:
p = new Intent(this,Map1Activity.class);
startActivity(p);
break;
default:
break;
}
}

@Override
protected void onResume() {
super.onResume();
Intent i = getIntent();
classes = i.getStringExtra("classes");
name =i.getStringExtra("name");
if(name != null && name.length() != 0){
toast = new Toast(this);
toast.makeText(MainActivity.this,"当前用户为:"+classes+""+name,Toast.LENGTH_LONG).show();
}
}
}
posted @ 2021-03-03 13:55  黄某人233  阅读(51)  评论(0编辑  收藏  举报