我一直在尝试让ListView出现在屏幕上,我必须遗漏一些因为它不起作用。 代码非常简单,从数据库中取出数据,然后在适配器和列表设置中生成一个字符串。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_singles);
db = new DbHelper(ViewSinglesAndAdd.this);
db.open();
this.all = db.getAllSingle();
db.close();
showList = (ListView) findViewById(R.id.listViewSingles);
if (all == null)
Toast.makeText(ViewSinglesAndAdd.this, "Empty", Toast.LENGTH_LONG)
.show();
if (all != null) {
String[] select = new String[all.size()];
for (int i = 0; i < all.size(); i++)
select[i] = all.elementAt(i).getPerson().toString();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
ViewSinglesAndAdd.this,
android.R.layout.simple_list_item_multiple_choice, select);
showList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
showList.setAdapter(adapter);
}
答案 0 :(得分:1)
如果all
代表您的字符串ArrayList
,那么您需要更改
select[i] = all.elementAt(i).getPerson().toString();
到
select[i] = all.get(i).getPerson();