AlertDialog 总是显示为空,这是当我传递字符串数组而不是适配器时的代码,但适配器是空的。我错过了什么吗?
.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Show dialog");
int selected =0; // select at 0
SimpleCursorAdapter Adapter =new SimpleCursorAdapter(MainActivity.this, android.R.layout.simple_list_item_single_choice,
null, new String[]{"title","title2"}, new int[]{android.R.id.text1});
builder.setSingleChoiceItems(
Adapter,
selected ,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
Toast.makeText(
MainActivity.this,
"Select "+choiceList[which],
Toast.LENGTH_SHORT
).show();
}
});
AlertDialog alert = builder.create();
alert.show();