我在采用ListView显示数据的时候、有2个字段都显示为fasle、使用的是SimpleAdapter适配器。
Debug发现读取出来的数据都是正常的。 SimpleAdapter sa = new SimpleAdapter(this, students, R.layout.item,
new String[] { "name", "sex", "age" }, new int[] { R.id.name,
R.id.sex, R.id.age });
listView.setAdapter(sa);经过适配器处理就成ffalse是啥原因?难道不能有中文吗?
// TODO Auto-generated method stub
List<Student> list = db.getScrollData(0, 20);
List<HashMap<String, Object>> students = new ArrayList<HashMap<String, Object>>();
for (Student student : list) {
HashMap<String, Object> hash = new HashMap<String, Object>();
hash.put("_id", student.get_id());
hash.put("name", student.getName());
hash.put("sex", student.getSex());
hash.put("age", student.getAge());
students.add(hash);
}
SimpleAdapter sa = new SimpleAdapter(this, students, R.layout.item,
new String[] { "name", "sex", "age" }, new int[] { R.id.name,
R.id.sex, R.id.age });
listView.setAdapter(sa); }
这是我activity里面的显示方法、我的意思是我debug到循环完成之后students里面的数据都是正常的。会不会和API、ADT之类的版本有关系?
new String[] { "name", "sex", "age" }, new int[] { R.id.name,
R.id.sex, R.id.age });
listView.setAdapter(sa);到这里执行之前数据都正常、我总不能打断点打到源码里面去吧、
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sqlite"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" /> <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<provider android:name=".StudentProvider" android:authorities="com.devil.provider.student">
</provider>
<activity
android:name=".SQLiteActivity"
android:label="@string/title_activity_sqlite" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="sql" /> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <uses-library android:name="android.test.runner" />
</application> <instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.sqlite" /></manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" > <TextView
android:textSize="22sp"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="@+id/name" /> <TextView
android:textSize="22sp"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@+id/sex" /> <TextView
android:textSize="22sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/age" /></LinearLayout>
android:textSize="22sp"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@+id/sex" /> <TextView
android:textSize="22sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/age" />android:text="@+id/sex",android:text="@+id/age"应该是这里的问题,将text改成id试试,楼主用android:text指定id,R文件竟然还能生成sex和age这两个id,很神奇……汗,可能是其他地方指定id时也用了sex和age吧
android:textSize="22sp"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@+id/sex" /> <TextView
android:textSize="22sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/age" />
就是他们错了,应该是id