73Android实验报告

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

创建一个名为“登录页面”的布局文件,该文件用于展示登录信息。程序界面如下图所示:packagecom.example.mylayout1;importandroid.app.Activity;importandroid.content.Context;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.os.Bundle;importandroid.view.Menu;importandroid.view.View;importandroid.widget.EditText;importandroid.widget.Toast;publicclassActivity01extendsActivity{EditTextname;EditTextpass;protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.myline);name=(EditText)findViewById(R.id.editText1);pass=(EditText)findViewById(R.id.editText2);}publicvoidclick(Viewview){Intentintent1=newIntent(this,Mylayout1MainActivity.class);startActivity(intent1);}publicvoidclick1(Viewview){SharedPreferencessf1=getSharedPreferences(account,Context.MODE_PRIVATE);Stringname1=sf1.getString(name,);Stringpass1=sf1.getString(pass,);Stringname2=name.getText().toString();Stringpass2=pass.getText().toString();if(name1.equals(name2)&&pass1.equals(pass2)){Intentintent2=newIntent(this,Textview1.class);intent2.putExtra(name,name1);intent2.putExtra(pass,pass1);startActivity(intent2);}else{Stringco=您的用户名或密码错误;Toast.makeText(this,co.toString(),1000).show();}}privateSharedPreferencesgetSharedPreference(){returnnull;}}创建一个名为“注册页面”的布局文件,该文件用于展示登录信息。程序界面如下图所示:packagecom.example.mylayout1;importandroid.os.Bundle;importandroid.app.Activity;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.content.SharedPreferences.Editor;importandroid.view.Menu;importandroid.view.View;importandroid.widget.CheckBox;importandroid.widget.EditText;importandroid.widget.RadioButton;importandroid.widget.RadioGroup;importandroid.widget.Spinner;importandroid.widget.TextView;publicclassMylayout1MainActivityextendsActivity{EditTextuname;EditTextupass;RadioButtonradio1;RadioButtonradio2;RadioGroupgroup1;Stringsex;Stringname;Stringpass;CheckBoxbox1;CheckBoxbox2;CheckBoxbox3;CheckBoxbox4;Stringstr1;Stringstr2;Stringstr3;Stringstr4;Spinnersp;Stringsp1;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.mylayout1_main);group1=(RadioGroup)findViewById(R.id.radioGroup1);uname=(EditText)findViewById(R.id.editText2);upass=(EditText)findViewById(R.id.editText3);box1=(CheckBox)findViewById(R.id.checkBox1);box2=(CheckBox)findViewById(R.id.checkBox2);box3=(CheckBox)findViewById(R.id.checkBox3);box4=(CheckBox)findViewById(R.id.checkBox4);sp=(Spinner)findViewById(R.id.spinner1);}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.getMenuInflater().inflate(R.menu.mylayout1_main,menu);returntrue;}publicvoidclick(Viewview){for(inti=0;igroup1.getChildCount();i++){radio1=(RadioButton)group1.getChildAt(i);if(radio1.isChecked()){sex=radio1.getText().toString();break;}}name=uname.getText().toString();pass=upass.getText().toString();if(box1.isChecked())str1=box1.getText().toString();elsestr1=;if(box2.isChecked())str2=box2.getText().toString();elsestr2=;if(box3.isChecked())str3=box3.getText().toString();elsestr3=;if(box4.isChecked())str4=box4.getText().toString();elsestr4=;sp1=(String)sp.getSelectedItem();Intentintent1=newIntent(this,Textview2.class);intent1.putExtra(name,name);intent1.putExtra(pass,pass);intent1.putExtra(sex,sex);intent1.putExtra(str,str1++str2++str3++str4);intent1.putExtra(sp1,sp1);startActivity(intent1);SharedPreferencessf1=getSharedPreferences(account,MODE_PRIVATE);Editoreditor=sf1.edit();editor.putString(name,name);editor.putString(pass,pass);editor.commit();}publicvoidclick1(Viewview){Intentintent2=newIntent(this,Activity01.class);startActivity(intent2);}}创建“登录成功页面”的界面交互代码,该程序实现用户信息显示。关键代码如下:packagecom.example.mylayout1;importandroid.os.Bundle;importandroid.app.Activity;importandroid.content.Intent;importandroid.view.Menu;importandroid.widget.TextView;publicclassTextview1extendsActivity{TextViewresult;protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_textview1);Intentintent1=getIntent();Stringstr1=intent1.getStringExtra(name);Stringstr2=intent1.getStringExtra(pass);result=(TextView)this.findViewById(R.id.text1);result.setText(您已登录成功+\n+用户名:+str1+\n+密码:+str2);}publicbooleanonCreateOptionsMenu(Menumenu){//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.getMenuInflater().inflate(R.menu.textview1,menu);returntrue;}}创建“用户信息显示界面”的界面交互代码,该程序实现用户信息显示。关键代码如下:packagecom.example.mylayout1;importandroid.os.Bundle;importandroid.app.Activity;importandroid.content.Intent;importandroid.view.Menu;importandroid.view.View;importandroid.widget.TextView;publicclassTextview2extendsActivity{TextViewview1;TextViewview2;TextViewview3;TextViewview4;TextViewview5;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_textview2);view1=(TextView)findViewById(R.id.textView1);view2=(TextView)findViewById(R.id.textView2);view3=(TextView)findViewById(R.id.textView3);view

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功