我有一个列表视图,但只有当我点击它们时才会显示这些项目。
这是我的代码:
MenuListItem selectedItem;
List<MenuListItem> menuItemList = new ArrayList<MenuListItem>();
menuItemList.addAll(resultResidents);
// Show dialog with list of menuListItems
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Selecteer resident");
builder.setIcon(contactIcon);
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
final ArrayAdapter<MenuListItem> arrayAdapter = new ArrayAdapter<MenuListItem>(
this, android.R.layout.simple_list_item_1,android.R.id.text1, menuItemList);
builder.setAdapter(arrayAdapter,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
selectedItem = arrayAdapter.getItem(item);
dialog.dismiss();
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
这是 menuItemList 类:
public class MenuListItem {
private String itemID,itemName;
public MenuListItem(String itemID, String itemName)
{
this.itemID = itemID;
this.itemName = itemName;
}
public String getItemID() {
return itemID;
}
public void setItemID(String itemID) {
this.itemID = itemID;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
@Override
public String toString() {
return this.itemName;
}
}
有什么帮助吗?