I have a listview but the items only display when I click on them.
This is my code:
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();
This is the menuItemList class :
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;
}
}
Any help?
Your items are there, they just aren’t visible because the text color is blending into the background. This is a bug with some of the styling of android layout. They fixed this in later versions of android but there are still some layouts that have this problem.
You can simply create your own simple_list_item with a custom font color to prevent the text from blending into the background to fix the problem.