【发布时间】:2012-04-28 22:02:10
【问题描述】:
我正在尝试让我的 AlertDialog 带有自定义列表视图,但似乎无法让它显示或运行而不会出现错误。
private void buildDialog(){
int selectedItem = -1; //somehow get your previously selected choice
LayoutInflater inflater = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
View customView = inflater.inflate(R.layout.listview, null, false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(customView);
builder.setTitle("Select Weapon").setCancelable(true);
builder.setSingleChoiceItems(inventory, selectedItem, "Desc", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
ListView lv = ((AlertDialog) dialog).getListView();
itemId = lv.getAdapter().getItemId(which);
new changeEQ().execute();
}
});
dialog = builder.create();
}
这是我的 AlertDialog,但不知道要添加什么来使用我的自定义布局、listview 和 listrow。我在网上浏览了指南,但它们显示的内容似乎对我没有用。 IE 我一定是做错了什么。
编辑:更改代码以包含答案,但屏幕上显示的内容没有变化。没有错误,但外观没有变化。
【问题讨论】:
-
能否提供您遇到的错误的 Logcat 输出
标签: android listview android-alertdialog