我正在尝试查看带有单选按钮的对话框,但是当我单击按钮时,警报对话框永远不会出现。下面是代码。请让我知道是否有任何替代解决方案。此示例取自 API Demos。
public class MainPage extends Activity{
Button start;
private static final int DIALOG_SINGLE_CHOICE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainpage);
start = (Button) findViewById(R.id.start);
start.setBackgroundResource(R.drawable.read);
start.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
showDialog(DIALOG_SINGLE_CHOICE );
}
});
}
@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
id = DIALOG_SINGLE_CHOICE;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose your option");
builder.setSingleChoiceItems(R.array.Baani, 0, new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Yes so do some stuff */
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked No so do some stuff */
}
})
.create();
return super.onCreateDialog(id);
}
}
}