- GOAL 1:当点击按钮时,如果没有选中任何单选按钮,它将通过 Toast 警告用户;如果选中了一个单选按钮,它将把用户带到新的活动中(或者对你做 smt up)。
第一的
public class hanh1_2 extends Activity{
public static int ButID;
@Override
二、设置按钮动作:
final Button ok2 = (Button) findViewById(R.id.ok2);
ok2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Set int of ButID = checkedradiobuttonID
//If ButID = -1 --> there isn't bt checked
int ButID = tieng.getCheckedRadioButtonId();
if (ButID == -1){
Toast.makeText(hanh1_2.this, "Check a butt pls", Toast.LENGTH_SHORT).show();
}
else {
Intent intent2 = new Intent(hanh1_2.this,hanh1_3.class);
startActivity(intent2);
}
}
});
对高级毫无意义,但可能对像我这样的新手有帮助:)