【发布时间】:2013-05-07 13:38:42
【问题描述】:
在我的 ListView 中,我这样保存数据:
public void listview_fuellen(){
DBHelper db = new DBHelper(this);
ListView lv = (ListView) findViewById(R.id.lvKinder);
Cursor c = db.select();
int count = c.getCount();
TextView tv = (TextView) findViewById(R.id.secondLine);
List<String> auswahl = new ArrayList<String>();
List<String> auswahl1 = new ArrayList<String>();
int i = 0;
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$1" + c.getCount());
while(c.moveToNext())
{
auswahl.add(c.getString(c.getColumnIndex("name")));
auswahl1.add(" " + i);
System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" + auswahl.get(i).toString());
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_black_text,R.id.firstLine, auswahl);
//ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, R.layout.list_black_text,R.id.secondLine, auswahl1);
lv.setAdapter(adapter);
}
现在,我从这里尝试了我的列表视图的布局:
http://android-developers.blogspot.co.at/2009/02/android-layout-tricks-1.html
现在,如何为每个 ListView-Item 或图标中的第二行设置值?
编辑:
我现在像这样尝试过,但那时我的列表视图中没有条目。
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();;
int i = 0;
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$1" + c.getCount());
while(c.moveToNext())
{
//map = new HashMap<String, String>();
map.put("name",c.getString(c.getColumnIndex("name")));
map.put("datum", c.getString(c.getColumnIndex("zeit")));
i++;
}
mylist.add(map);
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.list_black_text, new String[] { "datum",
"name" }, new int[] { R.id.firstLine, R.id.secondLine });
lv.setAdapter(mSchedule);
setListAdapter(mSchedule);
我做错了什么?
【问题讨论】:
-
使用带有自定义适配器的自定义列表视图
-
你能给我举个例子吗?如您所见,我尝试使用另一个适配器,但是当我将它添加到列表视图时,只显示其中一个
-
这是一个非常好的解释如何使用适配器以及哪个是最好的:piwai.info/android-adapter-good-practices
-
所以您认为使用 ArrayAdpater 这是不可能的?
-
如果您实现自定义数组适配器并扩展自定义视图,然后覆盖 getView 并在 getView 方法中设置文本。在使用创建自定义列表视图适配器时,您应该查看 ViewHolder 模式。这是一个很好的列表视图教程,包含自定义视图、自定义适配器和视图模式。 myandroidsolutions.blogspot.co.uk/2012/07/…
标签: android listview layout icons