標籤:tiny int spinner style sel getc toast override android
reg.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".RegisterActivity" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <TextView android:id="@+id/tvUsername" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_alignTop="@+id/textView2" android:text="使用者名稱" /> <TextView android:id="@+id/tvPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_below="@+id/textView2" android:layout_marginTop="16dp" android:text="密碼" /> <RadioGroup android:id="@+id/rdSex" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvPassword" android:layout_below="@+id/etPassword" android:layout_marginTop="22dp" > <RadioButton android:id="@+id/man" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="男" /> <RadioButton android:id="@+id/woman" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/rdSex" android:layout_centerHorizontal="true" android:text="女" /> </RadioGroup> <CheckBox android:id="@+id/cb_hb_std" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/rdSex" android:layout_below="@+id/rdSex" android:layout_marginTop="30dp" android:text="學習" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/cb_hb_photo" android:layout_alignLeft="@+id/cb_hb_std" android:text="愛好" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/cb_hb_std" android:layout_below="@+id/cb_hb_std" android:layout_marginTop="19dp" android:text="年齡" /> <Spinner android:id="@+id/spinnerAge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView4" android:layout_below="@+id/textView4" android:layout_marginTop="23dp" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/cb_hb_slp" android:layout_alignTop="@+id/spinnerAge" android:src="@drawable/ic_launcher" /> <ProgressBar android:id="@+id/pb" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView3" android:layout_toLeftOf="@+id/cb_hb_slp" android:visibility="gone" /> <Button android:id="@+id/btnCon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/spinnerAge" android:layout_alignParentBottom="true" android:text="確認" /> <CheckBox android:id="@+id/cb_hb_photo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView4" android:layout_alignRight="@+id/etRegUsername" android:layout_marginRight="44dp" android:text="攝影" /> <CheckBox android:id="@+id/cb_hb_slp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView4" android:layout_marginRight="18dp" android:layout_toLeftOf="@+id/cb_hb_photo" android:text="睡覺" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/rdSex" android:layout_below="@+id/etPassword" android:text="性別" /> <EditText android:id="@+id/etRegUsername" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/tvUsername" android:layout_toRightOf="@+id/cb_hb_std" android:ems="10" > <requestFocus /> </EditText> <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/tvPassword" android:layout_alignBottom="@+id/tvPassword" android:layout_alignLeft="@+id/etRegUsername" android:layout_alignRight="@+id/etRegUsername" android:ems="10" android:inputType="textPassword" /></RelativeLayout>
regSucc.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".RegSuccActivity" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <TextView android:id="@+id/cfName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_alignTop="@+id/textView2" android:text=" 1" /> <TextView android:id="@+id/cfSex" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_below="@+id/textView2" android:text="TextView" /> <TextView android:id="@+id/cfHobby" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/cfSex" android:layout_below="@+id/cfSex" android:layout_marginTop="28dp" android:text="TextView" /> <TextView android:id="@+id/cfSpinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/cfHobby" android:layout_below="@+id/cfHobby" android:layout_marginTop="33dp" android:text="TextView" /></RelativeLayout>
RegiserActivity.java
public class RegisterActivity extends Activity {private EditText etRegUsername;private RadioGroup rgSex;private Button btnCon;private Spinner spinnerAge;private ProgressBar pb;private CheckBox cb1;private CheckBox cb2;private CheckBox cb3;private List<CheckBox> checkBoxList = new ArrayList<CheckBox>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_register);List<String> listAge=new ArrayList<String>();listAge.add("18");listAge.add("19");listAge.add("20");listAge.add("21");spinnerAge=(Spinner)this.findViewById(R.id.spinnerAge);ArrayAdapter adapterAge=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,listAge);adapterAge.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spinnerAge.setAdapter(adapterAge);btnCon=(Button)this.findViewById(R.id.btnCon);pb=(ProgressBar)this.findViewById(R.id.pb);rgSex=(RadioGroup)findViewById(R.id.rdSex);etRegUsername=(EditText)findViewById(R.id.etRegUsername);cb1=(CheckBox)findViewById(R.id.cb_hb_slp);cb2=(CheckBox)findViewById(R.id.cb_hb_std);cb3=(CheckBox)findViewById(R.id.cb_hb_photo);checkBoxList.add(cb1); checkBoxList.add(cb2); checkBoxList.add(cb3);btnCon.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {pb.setVisibility(View.VISIBLE);Toast.makeText(RegisterActivity.this, "success", Toast.LENGTH_LONG).show();Intent itRegSuc=new Intent(RegisterActivity.this,RegSuccActivity.class);String hb =" ";for (CheckBox checkbox : checkBoxList) { if (checkbox.isChecked()){ hb+=checkbox.getText().toString() + " "; } } String name=etRegUsername.getText().toString();//Bundle bundle=new Bundle();// //傳遞name參數為tinyphp// bundle.putString("name", name);// itRegSuc.putExtras(bundle);RadioButton rbSex=(RadioButton)findViewById(rgSex.getCheckedRadioButtonId());String sex=rbSex.getText().toString();String sp=(String)spinnerAge.getSelectedItem();itRegSuc.putExtra("name", name);itRegSuc.putExtra("sex", sex);itRegSuc.putExtra("hobby", hb);itRegSuc.putExtra("spinner", sp);startActivity(itRegSuc);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.register, menu);return true;}}
RegSuccActivity.java
public class RegSuccActivity extends Activity {private TextView cfName;private TextView cfSex;private TextView cfHobby;private TextView cfSpinner;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_rsg_succ);//Bundle bundle = this.getIntent().getExtras();//String name=bundle.getString("name");Intent it=getIntent();String name=it.getStringExtra("name");String sex=it.getStringExtra("sex");String hb=it.getStringExtra("hobby");String spinner=it.getStringExtra("spinner");cfName=(TextView)findViewById(R.id.cfName);cfSex=(TextView)findViewById(R.id.cfSex);cfSpinner=(TextView)findViewById(R.id.cfSpinner);cfHobby=(TextView)findViewById(R.id.cfHobby);cfName.setText(name);cfSex.setText(sex);cfHobby.setText(hb);cfSpinner.setText(spinner);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.rsg_succ, menu);return true;}}
Android--普通註冊頁面實現(無功能)