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();
}
});
}
我制作了这个包含 ListView 的对话框,但是当您单击文本时只能选择项目,而不是像应该的那样在整行上选择项目。谁能找到我的错误?
编辑:
好的,解决了,我使用了一个构建器来制作对话框: https ://stackoverflow.com/a/6157258/2468567