我创建了一个包含4项活动的应用程序:登录,运动,技术和运动技术。 登录活动包含列表视图中的两个复选框(名为sport and technology)和一个按钮,当按下按钮时,程序会检查选中复选框的文本,并根据它打开正确的活动,如果只有运动复选框有已经检查过它应该打开体育活动,如果只选择了技术复选框,那么它将打开技术活动,如果两个复选框都被选中,那么它将打开一个名为“sporttecknology”的活动。 当运行应用程序时,当我只选择运动复选框然后按下按钮时,它会打开运动活动。但是当我只选择技术复选框然后按下按钮时,应用程序停止工作,当我同时选中这两个复选框时再按下按钮,
我的代码中有错误吗?
private void checkButtonClick(){
Button myButton = (Button) findViewById(R.id.findSelected);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer responseText = new StringBuffer();
//responseText.append("The following were selected...\n");
ArrayList<Interestclass> interestList = dataAdapter.interestList;
for (int i = 0; i < interestList.size(); i++) {
Interestclass interest = interestList.get(i);
if (interest.isSelected()) {
responseText.append(interest.getName());//"\n" +
}
}
Toast.makeText(getApplicationContext(), responseText, Toast.LENGTH_LONG).show();
String start = responseText.toString();
if (start.equals("Sport")) {
Intent intentSport = new Intent(MainActivity.this, Sport.class);
startActivity(intentSport);
}
else if (start.equals("Technology")) {
Intent intentTechnology = new Intent(MainActivity.this, Technology.class);
startActivity(intentTechnology);
}
else if (start.equals("SportTechnology")) {
Intent intentSportTech = new Intent(MainActivity.this, SportTechnology.class);
startActivity(intentSportTech);
}
else {
Intent intentTechnology = new Intent(MainActivity.this, Technology.class);
startActivity(intentTechnology);
}
/ * 开关(开始){ 案例“体育”: Intent intentSport = new Intent(MainActivity.this,Sport.class); startActivity(intentSport); 打破; 案例“技术”: Intent intentTechnology = new Intent(MainActivity.this,Technology.class); startActivity(intentTechnology); 打破; } * / }
});
}