我有一个列表视图,它的数据值由块(Item1,Item2...)分隔,但我想知道如何显示(Item 1,Sub Item 1...)?那么这里是只显示项目的代码,那么我如何显示项目和子项目呢?
代码:
//LISTVIEW database CONTATO
ListView user = (ListView) findViewById(R.id.lvShowContatos);
//String = simple value ||| String[] = multiple values/columns
String[] campos = new String[] {"nome", "telefone"};
list = new ArrayList<String>();
Cursor c = db.query( "contatos", campos, null, null, null, null, "nome" + " ASC ");
c.moveToFirst();
String lista = "";
if(c.getCount() > 0) {
while(true) {
list.add(c.getString(c.getColumnIndex("nome")).toString());
if(!c.moveToNext()) break;
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list);
user.setAdapter(adapter);
我放在那里的代码但仍然给我错误,我还没有看到它从哪里获取值。
//LISTVIEW database CONTATO
ListView user = (ListView) findViewById(R.id.lvShowContatos);
//String = simple value ||| String[] = multiple values/columns
String[] campos = new String[] {"nome", "telefone"};
ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> listItem;
Cursor c = db.query( "contatos", campos, null, null, null, null, "nome" + " ASC ");
c.moveToFirst();
listItem = new HashMap<String, Object>();
listItem.put("nome", "your_item_text");
listItem.put("telefone", "your_subitem_text");
items.add(listItem);
adapter = new SimpleAdapter(this, items, R.layout.custom_list_layout, new String[]{"item", "subitem"}, new int[]{R.id.text_item, R.id.text_subitem});
user.setAdapter(adapter);