public class MainActivity extends AppCompatActivity implements View.OnClickListener,RadioGroup.OnCheckedChangeListener{
//變數定義
private String str_phone="",str_pwd="";
private String str_sex="男";
private String str_hobby="";
private String str_city="";
private String str_result="";
private String[] city={"北京","上海","廣州","深圳"};
//組件定義
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)findViewById(R.id.etPhoneNo);
etPwd=(EditText)findViewById(R.id.etPwd);
rgSex=(RadioGroup) findViewById(R.id.rgSex);
rgSex.setOnCheckedChangeListener(this);
rbMale=(RadioButton) findViewById(R.id.rbMale);
rbFeMale=(RadioButton)findViewById(R.id.rbFeMale);
cbPlay= (CheckBox)findViewById(R.id.chkplay);
cbRead=(CheckBox)findViewById(R.id.chkRead);
cbSing=(CheckBox)findViewById(R.id.chkmusic);
spinner=(Spinner)findViewById(R.id.spinner);
btnLogin=(Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,city);
spinner.setAdapter(adapter);
spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
str_city=city[position];
}
});
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btnLogin:
str_hobby="";
str_phone=etPhoneNo.getText().toString();
str_pwd=etPwd.getText().toString();
if(cbRead.isChecked())
str_hobby+=cbRead.getText().toString()+" ";
if(cbPlay.isChecked())
str_hobby+=cbPlay.getText().toString()+" ";
if(cbSing.isChecked())
str_hobby+=cbSing.getText().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.id.rbMale){
str_sex="男生";
}else{
str_sex="女生";
}
}
}
做界面的時候沒有問題還能打開 我把監聽這些加進去就打不開app了
也沒有顯示錯誤 一直keep stopping
uj5u.com熱心網友回復:
看你的logcat日志,一定有報錯的地方,再不行你就先恢復,然后一點點加代碼,看加到哪報錯uj5u.com熱心網友回復:
2020/4/4
20:43 * daemon not running; starting now at tcp:5037
20:43 * daemon started successfully
20:43 Gradle sync started with single-variant sync
20:43 Project setup started
20:43 Gradle sync finished in 1 s 74 ms (from cached state)
20:43 Executing tasks: [:app:generateDebugSources] in project D:\Zhongjizuoye
20:43 NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
20:43 IDE and Plugin Updates: Android Studio is ready to update.
20:43 Gradle build finished in 19 s 416 ms
20:44 Executing tasks: [clean, :app:assembleDebug] in project D:\Zhongjizuoye
20:45 Gradle build finished in 27 s 409 ms
20:45 Executing tasks: [:app:assembleDebug] in project D:\Zhongjizuoye
20:45 Gradle build finished in 9 s 425 ms
20:45 Install successfully finished in 1 s 995 ms.
找不到問題
uj5u.com熱心網友回復:
這不是logcatuj5u.com熱心網友回復:
adb連上在cmd下 adb logcat > log.log 運行你的apk 把log.log打開 把對應的log貼出來
uj5u.com熱心網友回復:
logcat會有java程式出錯時那種提示資訊轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/45578.html
標籤:Android
上一篇:請問
