欢迎来到天天文库
浏览记录
ID:37708242
大小:53.00 KB
页数:5页
时间:2019-05-29
《Android期末考试复习资料》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.登录跳转Buttonbtn;EditTextname;EditTextpassword;OnClickListenerlis;protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn=(Button)findViewById(R.id.button1);name=(EditText)findViewById(R.id.editText1);pass
2、word=(EditText)findViewById(R.id.editText2);lis=newOnClickListener(){@OverridepublicvoidonClick(Viewarg0){//TODOAuto-generatedmethodstubStringnamestr=name.getEditableText().toString();Stringpwdstr=password.getEditableText().toString();switch(arg0.getId()){caseR.id.button1:i
3、f(namestr.equals("lk")&&pwdstr.equals("123456")){//startActivity(intent);//使用SharedPreferences保存数据SharedPreferencessf=getPreferences(Activity.MODE_PRIVATE);Editoredit=sf.edit();edit.putString("name",namestr);edit.putString("password",pwdstr);edit.commit();//提交当前数据Intentinte
4、nt=newIntent(MainActivity.this,SecondActivity.class);startActivity(intent);}else//使用Toast信息提示框提示成功写入数据Toast.makeText(MainActivity.this,"error",Toast.LENGTH_SHORT).show();break;}}};btn.setOnClickListener(lis);}2.Menu菜单publicclassMainActivityextendsActivity{TextViewtv;private
5、staticfinalintITEM1=Menu.FIRST;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tv=(TextView)findViewById(R.id.tv);}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){getMenuInflater().inflat
6、e(R.menu.main,menu);MenuItembegin=menu.getItem(0);OnMenuItemClickListenerlis=newOnMenuItemClickListener(){@OverridepublicbooleanonMenuItemClick(MenuItemitem){//TODOAuto-generatedmethodstubswitch(item.getItemId()){caseR.id.begin:Intentintent=newIntent(MainActivity.this,Secon
7、dActivity.class);startActivity(intent);break;}returnfalse;}};begin.setOnMenuItemClickListener(lis);returntrue;}}3.BroadcastReceiver广播publicclassMainActivityextendsActivity{Buttonbtn;OnClickListenerlis;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(s
8、avedInstanceState);setContentView(R.layout.activity_main);btn=(Button)findViewById
此文档下载收益归作者所有