我从sqlite的检索数据,并使用simpleadapter.I没有关于Layouts.Still仅供参考任何问题出在ListView它:实现simpleadapter使用HashMap的
list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<!-- Name Label -->
<TextView
android:id="@+id/subject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#421fc4"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/day"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:textStyle="bold" />
<TextView
android:id="@+id/slot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textColorHighlight="#782086"
android:textStyle="bold" />
<TextView
android:id="@+id/instructor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#782086"
android:textStyle="bold" />
</LinearLayout>
我有问题在下面的代码片段的某处。我试图从普通列表视图中检索sqlite的数据,它工作完美。但是当我使用此代码片段的自定义列表视图使用SimpleAdapter我只得到结果的最后一行在列表视图中最后一行的数据重复8次,因为结果中有8行查询。
HashMap<String, String> hashMap = new HashMap<String, String>();
ArrayList<HashMap<String, String>> Timetablelist;
//c being the cursor
if (c.moveToFirst()) {
do {
String subject = c.getString(c.getColumnIndex(dba.KEY_SUBJECT));
String day = c.getString(c.getColumnIndex(dba.KEY_DAY));
String slot = c.getString(c.getColumnIndex(dba.KEY_SLOT));
String instructor = c.getString(c.getColumnIndex(dba.KEY_INSTRUCTOR_NAME));
// adding each child node to HashMap key => value
hashMap.put("Subject", subject);
hashMap.put("Day", day);
hashMap.put("Slot", slot);
hashMap.put("Instructor", instructor);
Timetablelist.add(hashMap);
ListAdapter adapter = new SimpleAdapter(
this, Timetablelist,R.layout.list_item, new String[] { "Subject", "Day",
"Slot","Instructor" }, new int[] { R.id.subject,
R.id.day, R.id.slot,R.id.instructor });
setListAdapter(adapter);
}while (c.moveToNext());
}
P.S:我能够使用普通的listview检索数据。所以数据库和其他布局工作正常。
移动setListAdapter跳出DO的同时 – Raghunandan
还要移动适配器实例:'ListAdapter适配器=新SimpleAdapter(' – ramaral
移动的时候,做下段,以正确的,而循环,但仍然是相同的。最后一行在列表视图中重复8次。 –