今日总结:开始写体温登记系统!冲!今天写了登录界面及其与activity的交互
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"> <TextView android:id="@+id/tv_phone2" android:textSize="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请输入手机号" > </TextView> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/et_phone2" android:layout_toRightOf="@id/tv_phone2" ></EditText> <Button android:text="登录" android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.example.tiwen"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <!-- 这个权限用于进行网络定位--> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- 这个权限用于访问GPS定位--> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位--> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <!-- 获取运营商信息,用于支持提供运营商信息相关的接口--> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!-- 这个权限用于获取wifi的获取权限,wifi信息会用来进行网络定位--> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据--> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- 访问网络,网络定位需要上网 --> <uses-permission android:name="android.permission.INTERNET"/> <!-- 允许挂载和反挂载文件系统可移动存储 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!-- 允许程序读取底层系统日志文件 --> <uses-permission android:name="android.permission.READ_LOGS"/> <!-- 允许访问振动设备 --> <uses-permission android:name="android.permission.VIBRATE"/> <!-- 允许使用PowerManager的 WakeLocks保持进程在休眠时从屏幕消失 --> <uses-permission android:name="android.permission.WAKE_LOCK"/> <!-- 允许程序读取或写入系统设置 --> <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <!-- android 9.0上使用前台服务,需要添加权限 --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- 用于读取手机当前的状态 --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 读取缓存数据 --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 获取模拟定位信息 --> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" tools:ignore="ProtectedPermissions" /> <!-- 往SDCard写入数据权限 --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:name="com.example.LocationApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <!-- 声明service组件 --> <service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote"/> <!-- AK鉴权 --> <meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="BLv9k8LgRW1yRz8Ram2qOTfhZ21tV13Z"/> <!-- http://lbsyun.baidu.com/apiconsole/key --> <activity android:name=".DengLuActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.LocationApplication"/> <activity android:name="com.example.tiwen.MainActivity"/> <activity android:name="com.example.ZhuCeActivity"/> <activity android:name="com.example.tiwen.JieguoActivity"/> <activity android:name="com.example.tiwen.map"/> <activity android:name="com.example.tiwen.Hour_Adapter"/> <activity android:name="com.example.tiwen.zhexian"/> <activity android:name="com.example.Util"/> <activity android:name="com.example.Utils"/> <activity android:name="com.example.TemperatureView"/> <activity android:name="com.example.LocationService"/> </application> </manifest>
android:layout_height="wrap_content" android:id="@+id/denglu" ></Button> <Button android:text="注册" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/zhuce2" ></Button> <Button android:id="@+id/jieguo" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="查看结果" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="导出地图" android:id="@+id/ditu" ></Button> <Button android:id="@+id/daochu" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="导出折线图统计" ></Button> <Button android:id="@+id/delete" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="删除记录" /> </LinearLayout>
package com.example.tiwen; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import com.example.ZhuCeActivity; import com.example.litepaltest.Person; import com.example.litepaltest.banji; import org.litepal.LitePal; import org.litepal.LitePalApplication; import org.litepal.crud.LitePalSupport; import java.util.List; public class DengLuActivity extends AppCompatActivity implements View.OnClickListener { private String phone; private EditText et_phone; private String denglu; private Button bdenglu; int i=0; @Override public void onClick(View v) { switch (v.getId()) { case R.id.zhuce2: //点击注册按钮 Intent intent=new Intent(); intent.setClass(getApplicationContext(), ZhuCeActivity.class); startActivity(intent); break; case R.id.denglu: //点击登录按钮 phone=et_phone.getText().toString(); List<Person> persons= LitePal.findAll(Person.class); if(persons.size()>0) { for(Person ps:persons){ if(phone.equals(ps.getPhone())) { i = 1; break; } } } if(i==1) { Intent intent2 = new Intent(); intent2.putExtra("ph",phone); intent2.setClass(getApplicationContext(), MainActivity.class); startActivity(intent2); } else{ Toast.makeText(DengLuActivity.this, "登录失败,输入手机号未完成注册", Toast.LENGTH_SHORT).show(); } break; case R.id.jieguo: { Intent intent3=new Intent(); intent3.setClass(getApplicationContext(), JieguoActivity.class); startActivity(intent3); break; } case R.id.delete: { LitePal.deleteAll(banji.class); break; } case R.id.ditu: { Intent intent4=new Intent(); intent4.setClass(getApplicationContext(), map.class); startActivity(intent4); break; } case R.id.daochu: { Intent intent5=new Intent(); intent5.setClass(getApplicationContext(), zhexian.class); startActivity(intent5); Log.d("DengluActivity","123456"); break; } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.denglu); initUI(); et_phone=(EditText) findViewById(R.id.et_phone2); } private void initUI() { findViewById(R.id.denglu).setOnClickListener(this); findViewById(R.id.zhuce2).setOnClickListener(this); findViewById(R.id.jieguo).setOnClickListener(this); findViewById(R.id.delete).setOnClickListener(this); findViewById(R.id.ditu).setOnClickListener(this); findViewById(R.id.daochu).setOnClickListener(this); } }
运行截图: