public void onClick(View arg0) {
final Dialog dialog = new Dialog(Hero.this);
ListView list = new ListView(Hero.this);
final ArrayList<Spell> spells = new ArrayList<Spell>();
for (int i = 0; i < MainActivity.charSpells.size(); i++){
if (MainActivity.charSpells.get(i).getType() == Spell.SPELL){
spells.add(MainActivity.charSpells.get(i));
}
}
list.setAdapter(new ArrayAdapter<Spell>(Hero.this, R.layout.row, spells));
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(list);
dialog.setCanceledOnTouchOutside(true);
dialog.show();
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
spell1.setText(spells.get(arg2).getSc());
MainActivity.spells[0] = spells.get(arg2);
dialog.dismiss();
}
});
}
I made this Dialog which contain a ListView, but the items can ony be selected when you click on the text and not, like it should be, on the whole row. Can anyone find my mistake?
EDIT:
OK, solved it, I used a builder to make the dialog: https://stackoverflow.com/a/6157258/2468567