1、创立一种名为“登录页面”旳布局文献,该文献用于展示登录信息。程序界面如下图所示:package com.example.mylayout1;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.Edi
2、tText;import android.widget.Toast;public class Activity01 extends Activity EditText name;EditText pass ;protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.myline);name=(EditText)findViewById(R.id.editText1);pass=(EditText)findViewById(R.id.e
3、ditText2);public void click(View view)Intent intent1=new Intent(this,Mylayout1MainActivity.class);startActivity(intent1);public void click1(View view)SharedPreferences sf1=getSharedPreferences(account,Context.MODE_PRIVATE);String name1=sf1.getString(name,);String pass1=sf1.getString(pass,);String na
4、me2=name.getText().toString();String pass2=pass.getText().toString();if(name1.equals(name2)&pass1.equals(pass2)Intent intent2=new Intent(this, Textview1.class);intent2.putExtra(name, name1);intent2.putExtra(pass, pass1);startActivity(intent2);elseString co=您旳顾客名或密码错误;Toast.makeText(this, co.toString
5、(), 1000).show();private SharedPreferences getSharedPreference() return null;创立一种名为“注册页面”旳布局文献,该文献用于展示登录信息。程序界面如下图所示:package com.example.mylayout1;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.content.Shared
6、Preferences.Editor;import android.view.Menu;import android.view.View;import android.widget.CheckBox;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Spinner;import android.widget.TextView;public class Mylayout1MainActivity extend
7、s Activity EditText uname;EditText upass;RadioButton radio1;RadioButton radio2;RadioGroup group1;String sex;String name;String pass;CheckBox box1;CheckBox box2;CheckBox box3;CheckBox box4;String str1;String str2;String str3;String str4;Spinner sp;String sp1;Overrideprotected void onCreate(Bundle sav
8、edInstanceState) 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)findView
9、ById(R.id.checkBox2);box3=(CheckBox)findViewById(R.id.checkBox3);box4=(CheckBox)findViewById(R.id.checkBox4);sp=(Spinner)findViewById(R.id.spinner1) ;Overridepublic boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate
10、(R.menu.mylayout1_main, menu);return true;public void click(View view)for(int i=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=box
11、1.getText().toString();else str1=;if(box2.isChecked()str2=box2.getText().toString();else str2=;if(box3.isChecked()str3=box3.getText().toString();else str3=;if(box4.isChecked()str4=box4.getText().toString();else str4=;sp1=(String)sp.getSelectedItem(); Intent intent1=new Intent(this,Textview2.class);
12、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); SharedPreferences sf1=getSharedPreferences(account,MODE_PRIVATE); Editor editor=sf1.edit(); editor.putString(n
13、ame, name); editor.putString(pass, pass); editor mit();public void click1(View view)Intent intent2=new Intent(this,Activity01.class);startActivity(intent2);创立“登录成功页面”旳界面交互代码,该程序实现顾客信息显示。关键代码如下:package com.example.mylayout1;import android.os.Bundle;import android.app.Activity;import android.content.I
14、ntent;import android.view.Menu;import android.widget.TextView;public class Textview1 extends Activity TextView result;protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_textview1);Intent intent1=getIntent();String str1=intent1.getSt
15、ringExtra(name);String str2=intent1.getStringExtra(pass);result=(TextView)this.findViewById(R.id.text1);result.setText(您已登录成功+n+顾客名:+str1+n+密码:+str2);public boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.
16、textview1, menu);return true;创立“顾客信息显示界面”旳界面交互代码,该程序实现顾客信息显示。关键代码如下:package com.example.mylayout1;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.widget.TextView;public class Textview2 extends Activit
17、y TextView view1;TextView view2;TextView view3;TextView view4;TextView view5;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_textview2);view1=(TextView)findViewById(R.id.textView1);view2=(TextView)findViewById(R.id.textVi
18、ew2);view3=(TextView)findViewById(R.id.textView3);view4=(TextView)findViewById(R.id.textView4);view5=(TextView)findViewById(R.id.textView5);Intent intent1=getIntent();String name=intent1.getStringExtra(name);String pass=intent1.getStringExtra(pass);String sex=intent1.getStringExtra(sex);String str=i
19、ntent1.getStringExtra(str);String sp1=intent1.getStringExtra(sp1);view1.setText(name);view2.setText(pass);view3.setText(sex);view4.setText(str);view5.setText(sp1);public void click1(View view)Intent intent1=new Intent(this, Activity01.class);startActivity(intent1);Overridepublic boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.textview2, menu);return true;