1
我有以下的alertdialog代码:如何知道在alertdialog中单击确定按钮时单击哪个单选按钮?
AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("Options");
helpBuilder.setMessage("Choose Your Option");
LayoutInflater inflater = getLayoutInflater();
View radioButtonLayout = inflater.inflate(R.layout.popuplayout, null);
byNameRadioButton = (RadioButton) findViewById(R.id.byname);
byIdRadioButton = (RadioButton) findViewById(R.id.byid);
helpBuilder.setView(radioButtonLayout);
helpBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Tab1Activity.this,
"Ok button is clicked", Toast.LENGTH_LONG)
.show();
}
}
});
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
我想知道点击了哪个单选按钮被点击OK OK按钮时? 需要帮助。 Thanx!
没错,默认版本是比较有用的,那么你用OK按钮。 – asktomsk 2012-03-22 09:33:50
为什么没有这个代码工作? okButton =(Button)findViewById(R.id.ok); \t \t okButton.setOnClickListener(新View.OnClickListener(){ \t \t \t公共无效的onClick(视图v){// 上面的代码ü提 \t \t \t \t \t \t \t} \t \t} );' 点击oK按钮,alertdialog应该出现,但没有任何反应。 – captaindroid 2012-03-22 09:44:35
确切的代码我写道: 'okButton.setOnClickListener(新View.OnClickListener(){ 公共无效的onClick(视图v){ 最终的CharSequence []项目= { “ByScore”, “绰号”, “ById”}; \t \t \t \t AlertDialog.Builder助洗剂=新AlertDialog.Builder(Tab1Activity.this); \t \t \t \t builder.setTitle( “选项”); \t \t \t \t builder.setSingleChoiceItems(项,-1, \t \t \t \t \t \t新DialogInterface.OnClickListener(){ \t \t \t \t \t \t \t公共无效的onClick(DialogInterface对话,诠释项){ \t \t \t \t \t \t \t \t Toast.makeText(getApplicationContext(), \t \t \t \t \t \t \t \t \t \t it ems [item],Toast.LENGTH_SHORT).show(); \t \t \t \t \t \t \t} \t \t \t \t \t \t}); AlertDialog alert = builder。创建(); }}); ' – captaindroid 2012-03-22 09:48:19