gpt4 book ai didi

java - Android - 更改ListView项目的TextStyle

转载 作者:行者123 更新时间:2023-12-01 19:11:33 25 4
gpt4 key购买 nike

我正在开发一个具有项目 ListView 的 Android 应用程序。这些 ListView 记录是从 sqlite 数据库中查询的。下面是 ListView 的实现代码:

       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>

这里我的问题是通过更改 ListView 项的文本样式来区分同一 list1.xml 中具有 'a'=null 和 'a'=notnull 的数据记录...... 我可以通过在查询中提供任何文本样式属性来区分 SQL 查询中的文本样式吗?

请帮助我提供示例代码/链接......提前致谢

最佳答案

您可以使用 ListView 的 CustomAdapter 来完成此操作。由于 View 是从包含所有光标结果的自定义数据对象创建的。您可以检查 a 是否为空并且 TextView 具有不同的文本样式

检查this自定义适配器的练习

关于java - Android - 更改ListView项目的TextStyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8223403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com