I am developing one Android application having the list view of items. Those listview records are queried form the sqlite database. Here is the code of list view implementation:
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);
where list1.xml is:
<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>
Here my problem is to differentiate the data records having ‘a’=null and ‘a’=notnull from the same list1.xml by changing the text style of the list view items…. Can I differentiate the text style in the sql query by giving any text style attributes in the query?
Please help me with the sample code/links…… Thanks in advance
You can do this using a CustomAdapter for the ListView . Since the View is created from the custom data object which incudes all the cursor results.
You can check if a is null and have a different textstyle for the textview
Check this exercise for a custom adapter