我的TextView可以获得此对话框的消息,如下所示:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("your message");
AlertDialog dialog = builder.show();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
但是,如何将这些字符串项添加到TextView ???
final CharSequence[] items = { "String 1", "String 2", "String 3" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(items,new DialogInterface.OnClickListener(....
AlertDialog dialog = builder.show();
TextView item = (TextView)dialog.findViewById(android.R.id.?);
请帮助我~~
答案 0 :(得分:1)
这些是列表项,而不是TextView。您将在setItems
方法的回调中获取所选项目
builder.setItems(items, new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which) {
String chosen = items[which].toString();
}
});