每日总结3.30
每日总结:
所花时间:6h
代码量:300行
博客量:1篇
————————————~~~~~~刷~~~~~————————————————
今天课下的学习内容主要是安卓的结对作业的完善,我这里已经基本完善了,下面给出三种功能的输出界面和部分代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | <?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" android:layout_margin= "10dp" android:orientation= "vertical" > <RadioGroup android:id= "@+id/rg_login" android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <RadioButton android:id= "@+id/rb_password" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" android:checked= "true" android:text= "密码登录" android:textColor= "@color/black" android:textSize= "17dp" /> <RadioButton android:id= "@+id/rb_verifycode" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" android:text= "验证码登录" android:textColor= "@color/black" android:textSize= "17dp" /> </RadioGroup> <LinearLayout android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <TextView android:layout_width= "wrap_content" android:layout_height= "match_parent" android:gravity= "center" android:text= "手机号码:" android:textColor= "@color/black" android:textSize= "17dp" /> <EditText android:id= "@+id/et_phone" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_marginTop= "5dp" android:layout_marginBottom= "5dp" android:layout_weight= "1" android:background= "@drawable/editext_selector" android:hint= "请输入手机号码" android:inputType= "number" android:maxLength= "11" android:textColor= "@color/black" android:textColorHint= "@color/grey" android:textSize= "17dp" /> </LinearLayout> <LinearLayout android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <TextView android:id= "@+id/tv_password" android:layout_width= "wrap_content" android:layout_height= "match_parent" android:gravity= "center" android:text= "登陆密码:" android:textColor= "@color/black" android:textSize= "17dp" /> <RelativeLayout android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" > <EditText android:id= "@+id/et_password" android:layout_width= "match_parent" android:layout_height= "match_parent" android:layout_marginTop= "5dp" android:layout_marginBottom= "5dp" android:layout_weight= "1" android:background= "@drawable/editext_selector" android:hint= "请输入密码" android:inputType= "numberPassword" android:textColor= "@color/black" android:textColorHint= "@color/grey" android:textSize= "17dp" /> <Button android:id= "@+id/btn_forget" android:layout_width= "wrap_content" android:layout_height= "match_parent" android:layout_alignParentEnd= "true" android:text= "忘记密码" android:textColor= "@color/white" android:textSize= "17dp" /> </RelativeLayout> </LinearLayout> <CheckBox android:id= "@+id/ck_remember" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:text= "记住密码" android:textColor= "@color/black" android:textSize= "17dp" /> <Button android:id= "@+id/btn_login" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:text= "登录" android:textColor= "@color/white" android:textSize= "17dp" /> </LinearLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | package com.example.subway; import androidx.activity.result.ActivityResult; import androidx.activity.result.ActivityResultCallback; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; import java.util.Random; public class LoginActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, View.OnClickListener { private EditText et_phone; private EditText et_password; private TextView tv_password; private Button btn_forget; private CheckBox ck_remember; private RadioGroup rb_login; private RadioButton rb_password; private RadioButton rb_verifycode; private ActivityResultLauncher<Intent> register; private Button btn_login; private String mPassword = "123456789" ; private String mVerifyCode; private SharedPreferences preferences; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_login); rb_login = findViewById(R.id.rg_login); tv_password = findViewById(R.id.tv_password); et_password = findViewById(R.id.et_password); et_phone = findViewById(R.id.et_phone); btn_forget = findViewById(R.id.btn_forget); ck_remember = findViewById(R.id.ck_remember); rb_password = findViewById(R.id.rb_password); rb_verifycode = findViewById(R.id.rb_verifycode); btn_login = findViewById(R.id.btn_login); register = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() { @Override public void onActivityResult(ActivityResult result) { Intent intent = result.getData(); if (intent != null && result.getResultCode() == Activity.RESULT_OK) { mPassword = intent.getStringExtra( "new_password" ); } } }); rb_login.setOnCheckedChangeListener( this ); btn_forget.setOnClickListener( this ); btn_login.setOnClickListener( this ); preferences = getSharedPreferences( "config" , Context.MODE_PRIVATE); reload(); } private void reload() { boolean isRemember=preferences.getBoolean( "isRemember" , false ); if (isRemember){ String phone = preferences.getString( "phone" , null ); String password = preferences.getString( "password" , null ); if (phone != null ) { et_phone.setText(phone); } if (password != null && password.equals(mPassword)) { et_password.setText(password); ck_remember.setChecked( true ); } } } @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i) { case R.id.rb_password: tv_password.setText( "登陆密码:" ); et_password.setHint( "请输入密码" ); //btn_forget.setVisibility(View.GONE); btn_forget.setVisibility(View.GONE); ck_remember.setVisibility(View.VISIBLE); break ; case R.id.rb_verifycode: tv_password.setText( " 验证码:" ); et_password.setHint( "请输入验证码" ); btn_forget.setText( "获取验证码" ); ck_remember.setVisibility(View.GONE); //btn_forget.setVisibility(View.VISIBLE); break ; } } @Override public void onClick(View view) { String phone = et_phone.getText().toString(); switch (view.getId()) { case R.id.btn_forget: if (phone.length() < 11) { Toast.makeText( this , "请输入正确的手机号" , Toast.LENGTH_SHORT).show(); return ; } if (rb_verifycode.isChecked()) { mVerifyCode = String.format( "%06d" , new Random().nextInt(999999)); Toast.makeText( this , mVerifyCode, Toast.LENGTH_SHORT).show(); } break ; case R.id.btn_login: if (rb_password.isChecked()) { if (!mPassword.equals(et_password.getText().toString())) { Toast.makeText( this , "请输入正确的密码" , Toast.LENGTH_SHORT).show(); return ; } if (ck_remember.isChecked()) { SharedPreferences.Editor editor = preferences.edit(); editor.putString( "phone" ,et_phone.getText().toString()); editor.putString( "password" , et_password.getText().toString()); editor.putBoolean( "isRemember" ,ck_remember.isChecked()); editor.commit(); } loginSuccess(); } else if (rb_verifycode.isChecked()) { if (!mVerifyCode.equals(et_password.getText().toString())) { Toast.makeText( this , "请输入正确的验证码" , Toast.LENGTH_SHORT).show(); return ; } loginSuccess(); } break ; } } private void loginSuccess() { String phone = et_phone.getText().toString(); Toast.makeText( this , "登录成功" , Toast.LENGTH_SHORT).show(); Intent intent = new Intent( this , MenuActivity. class ); register.launch(intent); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <?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" android:layout_margin= "10dp" android:gravity= "center" android:orientation= "vertical" > <Button android:id= "@+id/btn_line" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "路线查询" android:textColor= "@color/white" android:textSize= "40dp" /> <Button android:id= "@+id/btn_site" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "站点查询" android:textColor= "@color/white" android:textSize= "40dp" /> <Button android:id= "@+id/btn_best" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "最短线路查询" android:textColor= "@color/white" android:textSize= "40dp" /> </LinearLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | package com.example.subway; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MenuActivity extends AppCompatActivity implements View.OnClickListener { private Button btn_site; private Button btn_line; private Button btn_best; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_menu); btn_line = findViewById(R.id.btn_line); btn_site = findViewById(R.id.btn_site); btn_best = findViewById(R.id.btn_best); btn_line.setOnClickListener( this ); btn_site.setOnClickListener( this ); btn_best.setOnClickListener( this ); } @Override public void onClick(View view) { Intent intent = new Intent(); switch (view.getId()){ case R.id.btn_line: intent.setClass(MenuActivity. this , LineActivity. class ); startActivity(intent); break ; case R.id.btn_site: intent.setClass(MenuActivity. this , SiteActivity. class ); startActivity(intent); break ; case R.id.btn_best: intent.setClass(MenuActivity. this , BestActivity. class ); startActivity(intent); break ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <?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" android:gravity= "center" android:orientation= "vertical" > <LinearLayout android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <TextView android:layout_width= "wrap_content" android:layout_height= "match_parent" android:gravity= "center" android:text= "线路:" android:textColor= "@color/black" android:textSize= "17dp" /> <EditText android:id= "@+id/et_line" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_marginTop= "5dp" android:layout_marginBottom= "5dp" android:layout_weight= "1" android:background= "@drawable/editext_selector" android:hint= "请输入要查询的线路" android:inputType= "text" android:textColor= "@color/black" android:textColorHint= "@color/grey" android:textSize= "17dp" /> </LinearLayout> <Button android:id= "@+id/btn_line" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "线路查询" android:textColor= "@color/white" android:textSize= "20dp" /> <TextView android:id= "@+id/tv_line" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:paddingTop= "10dp" android:paddingBottom= "10dp" android:textSize= "25sp" /> </LinearLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package com.example.subway; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class LineActivity extends AppCompatActivity implements View.OnClickListener { private TextView tv_line; private Button btn_line; private EditText et_line; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_line); tv_line = findViewById(R.id.tv_line); et_line = findViewById(R.id.et_line); btn_line = findViewById(R.id.btn_line); btn_line.setOnClickListener( this ); } @Override public void onClick(View view) { String line=et_line.getText().toString(); switch (line){ case "2号线" : tv_line.setText( "积水潭,鼓楼大桥,安定门,雍和宫,东直门,东四十条,朝阳门,建国门,北京站,崇文门,前门,和平门,宣武门,长椿街,复兴门,阜成门,车公庄,西直门" ); break ; case "5号线" : tv_line.setText( "宋家庄,刘家窑,蒲黄榆,天坛东门,磁器口,崇文门,东单,灯市口,东四,张自忠路,北新桥,雍和宫,和平里北街,和平西桥,惠新西街南口,惠新西街北口,大屯路东,北苑路北,立水桥南,立水桥,天通苑南,天通苑,天通苑北" ); break ; case "燕房线" : tv_line.setText( "阎村东,紫草坞,阎村,星城,大石河东,马各庄,饶乐府,房山城关,燕山" ); break ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | <?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" android:gravity= "center" android:orientation= "vertical" > <LinearLayout android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <TextView android:layout_width= "wrap_content" android:layout_height= "match_parent" android:gravity= "center" android:text= "起始站:" android:textColor= "@color/black" android:textSize= "17dp" /> <EditText android:id= "@+id/et_star" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_marginTop= "5dp" android:layout_marginBottom= "5dp" android:layout_weight= "1" android:background= "@drawable/editext_selector" android:hint= "请输入起始站" android:inputType= "text" android:textColor= "@color/black" android:textColorHint= "@color/grey" android:textSize= "17dp" /> </LinearLayout> <LinearLayout android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <TextView android:layout_width= "wrap_content" android:layout_height= "match_parent" android:gravity= "center" android:text= "终点站:" android:textColor= "@color/black" android:textSize= "17dp" /> <EditText android:id= "@+id/et_end" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_marginTop= "5dp" android:layout_marginBottom= "5dp" android:layout_weight= "1" android:background= "@drawable/editext_selector" android:hint= "请输入终点站" android:inputType= "text" android:textColor= "@color/black" android:textColorHint= "@color/grey" android:textSize= "17dp" /> </LinearLayout> <Button android:id= "@+id/btn_best" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "最优路线查询" android:textColor= "@color/white" android:textSize= "20dp" /> <TextView android:id= "@+id/tv_best" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:paddingTop= "10dp" android:paddingBottom= "10dp" android:textSize= "25sp" /> </LinearLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | package com.example.subway; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class BestActivity extends AppCompatActivity implements View.OnClickListener { private TextView tv_best; private EditText et_star; private EditText et_end; private Button btn_best; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_best); tv_best = findViewById(R.id.tv_best); et_star = findViewById(R.id.et_star); et_end = findViewById(R.id.et_end); btn_best = findViewById(R.id.btn_best); btn_best.setOnClickListener( this ); } @Override public void onClick(View view) { String star=et_star.getText().toString(); String end=et_end.getText().toString(); switch (star){ case "北京西站" : tv_best.setText( "北京西站,湾子,达官营,广安门内,菜市口(换乘4号线),陶然亭,北京南站" ); break ; case "十里河" : tv_best.setText( "十里河,潘家园,劲松,双井,国贸(换乘1号线),永安里,建国门,东单,王府井" ); break ; case "公主坟" : tv_best.setText( "公主坟,军事博物馆,木樨地,南礼士路,复兴门,西单,天安门西,天安门东,王府井" ); break ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <?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" android:gravity= "center" android:orientation= "vertical" > <LinearLayout android:layout_width= "match_parent" android:layout_height= "50dp" android:orientation= "horizontal" > <TextView android:layout_width= "wrap_content" android:layout_height= "match_parent" android:gravity= "center" android:text= "站点:" android:textColor= "@color/black" android:textSize= "17dp" /> <EditText android:id= "@+id/et_site" android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_marginTop= "5dp" android:layout_marginBottom= "5dp" android:layout_weight= "1" android:background= "@drawable/editext_selector" android:hint= "请输入要查询的站点" android:inputType= "text" android:textColor= "@color/black" android:textColorHint= "@color/grey" android:textSize= "17dp" /> </LinearLayout> <Button android:id= "@+id/btn_site" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "站点查询" android:textColor= "@color/white" android:textSize= "20dp" /> <TextView android:id= "@+id/tv_site" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:paddingTop= "10dp" android:paddingBottom= "10dp" android:textSize= "25sp" /> </LinearLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | package com.example.subway; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class SiteActivity extends AppCompatActivity implements View.OnClickListener { private TextView tv_site; private EditText et_site; private Button btn_site; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_site); tv_site = findViewById(R.id.tv_site); et_site = findViewById(R.id.et_site); btn_site = findViewById(R.id.btn_site); btn_site.setOnClickListener( this ); } @Override public void onClick(View view) { String site=et_site.getText().toString(); switch (site){ case "古城" : tv_site.setText( "经过:1号线" ); break ; case "公主坟" : tv_site.setText( "经过:1号线,10号线" ); break ; case "平安里" : tv_site.setText( "经过:4号线,6号线" ); break ; } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通