我正在开发一个具有项目列表视图的Android应用程序。这些列表视图记录是从sqlite数据库中查询的。以下是列表视图实现的代码:
DataBaseHelper myDbHelper = new DataBaseHelper(null);
myDbHelper = new DataBaseHelper(this);
private static final String fields[] = {"c"};
int[] names = new int[] {R.id.name};
client1 = (ListView)findViewById(R.id.list1 );
String sql = "SELECT sno,a,b,c,d FROM (SELECT com.sno, com.a, com.b com.c,cd.d from table1 mem inner join table2 cd on mem.e=cd.e inner join table3 com on com.b = mem.b where mem.e =14445 AND a is NULL UNION SELECT com.sno, com.a, com.b,com.c,cd.d from table1 mem inner join table3 com on com.b = mem.b inner join table2 cd on mem.e=cd.e where mem.e =14445 AND a is NOT NULL) a group by a,b;";
Cursor cdata = myDbHelper.getView(sql);
SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this,R.layout.list1, cdata, fields,names );
client1.setAdapter(adapter2); 其中list1.xml是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/MainLayout"
android:padding="5px">
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#104082"
android:textStyle="bold"
android:layout_weight="1"
/>
</LinearLayout> 这里,我的问题是通过更改列表视图项的文本样式,将具有'a'=null和'a'=notnull的数据记录与相同的list1.xml区分开来.可以通过在查询中提供任何文本样式属性来区分查询中的文本样式吗?
请帮我查一下代码/链接.提前感谢
发布于 2011-11-22 07:40:58
您可以使用用于CustomAdapter的ListView来完成此操作。因为视图是从包含所有游标结果的自定义数据对象创建的。可以检查文本视图是否为null,并具有不同的文本样式。
检查自定义适配器的这练习
发布于 2011-11-22 07:40:49
您必须定义一个自定义列表适配器,在其中您必须定义getitemview方法,您可以在其中膨胀(或以编程方式更改)项的布局,比如list1_null.xml或list1_notnull.xml。
如果您需要的不仅仅是简单地显示值(甚至是更改颜色),您就必须重新定义一个自定义适配器。
来自android的ListAdapter示例:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List4.html
https://stackoverflow.com/questions/8223403
复制相似问题