Public class MainActivity extends AppCompatActivity implements the View. An OnClickListener, RadioGroup. OnCheckedChangeListener {
//variable definition
Private String str_phone=", "str_pwd=" ";
Private String str_sex="male";
Private String str_hobby="";
Private String str_city="";
Private String str_result="";
Private String [] city={" Beijing ", "Shanghai", "guangzhou", "shenzhen"};
//component definition
Private EditText etPhoneNo etPwd;
Private RadioGroup rgSex;
Private RadioButton rbMale rbFeMale;
Private CheckBox cbRead cbSing, cbPlay;
Private Spinner Spinner.
Private Button btnLogin;
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
Private void init () {
EtPhoneNo=(EditText) the findViewById (R.i d.e tPhoneNo);
EtPwd=(EditText) the findViewById (R.i d.e tPwd);
RgSex=(RadioGroup) the findViewById (R.i d.r gSex);
RgSex. SetOnCheckedChangeListener (this);
RbMale=(RadioButton) the findViewById (R.i d.r bMale);
RbFeMale=(RadioButton) the findViewById (R.i d.r bFeMale);
CbPlay=(CheckBox) the findViewById (R.i, dc hkplay);
CbRead=(CheckBox) the findViewById (R.i, dc hkRead);
CbSing=(CheckBox) the findViewById (R.i, dc hkmusic);
Spinner=(spinner) the findViewById (R.i d.s pinner);
BtnLogin=(Button) the findViewById (R.i db tnLogin);
BtnLogin. SetOnClickListener (this);
ArrayAdapter adapter=new ArrayAdapter (this, android R.l ayout. Simple_expandable_list_item_1, city);
Spinner. SetAdapter (adapter);
Spinner. SetOnItemClickListener (new AdapterView. OnItemClickListener () {
@ Override
Public void onItemClick (AdapterView<?> The parent, View View, int position, long id) {
Str_city=city [position];
}
});
}
@ Override
Public void onClick (View View) {
The switch (the getId ()) {
Case R.i db tnLogin:
Str_hobby="";
Str_phone=etPhoneNo. GetText (). The toString ();
Str_pwd=etPwd. GetText (). The toString ();
If (cbRead isChecked ())
Str_hobby +=cbRead. GetText (). The toString () + "";
If (cbPlay isChecked ())
Str_hobby +=cbPlay. GetText (). The toString () + "";
If (cbSing isChecked ())
Str_hobby +=cbSing. GetText (). The toString () + "";
Intent Intent=new Intent (MainActivity. This, SecondActivity. Class);
Bundle Bundle=new Bundle ();
Bundle. PutString (" phone ", str_phone);
Bundle. PutString (" PWD ", str_pwd);
Bundle. PutString (" sex ", str_sex);
Bundle. PutString (" hobby ", str_hobby);
Bundle. PutString (" city ", str_city);
Intent. PutExtras (bundle);
startActivity(intent);
break;
}
}
@ Override
Public void onCheckedChanged (RadioGroup group, int checkedId) {
If (checkedId==R.i d.r bMale) {
Str_sex="boys";
} else {
Str_sex="girls";
}
}
}
Interface to do no problem when I can open my listening these in and you can't open the app
No display error has been keep stopping
CodePudding user response:
Look at your logcat log, there must be an error, can't you just restore again, and then a little bit of code, to which an errorCodePudding user response: