2011-11-22 78 views
0

我正在开发一个具有项目列表视图的Android应用程序。这些listview记录是从sqlite数据库查询的。下面是列表视图执行代码:Android - 更改ListView项目的TextStyle

 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'=数据记录通过更改列表视图项目的文本样式,从同一个list1.xml中的notnull ....可以通过在查询中提供任何文本样式属性来区分sql查询中的文本样式吗?

提前

回答

2

可以使用为ListView一个CustomAdapter做到这一点。由于视图是从包含所有游标结果的自定义数据对象创建的。 您可以检查是否为空,并有不同的文本样式为TextView的

检查this锻炼自定义适配器

2

请帮我与示例代码/链接......感谢你必须定义一个自定义列表适配器和它,你必须定义一个膨胀getitemview方法(或编程更改)该项目的布局,可以说list1_null.xml或list1_notnull.xml

如果您需要的不仅仅是简单显示值(甚至是更改颜色等),您必须重新定义自定义适配器。从Android的API

ListAdapter例如:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List4.html