How to Implement Custom List View for the list Items in Android Application

Posted by avadhani on Stack Overflow See other posts from Stack Overflow or by avadhani
Published on 2011-11-28T09:37:18Z Indexed on 2011/11/28 9:52 UTC
Read the original article Hit count: 239

Filed under:
|
|
|

I had a problem with the list view having both parent list and the child list of the list activity(implemented through database query). I wish to show them differing their properties by changing the text style (parent list items are in bold, child list items are in normal style). The following is the code from which all the child and parent list items having the same style(bold):

       String sql = "SELECT Parentid,Childid,Name from (select com.Parentid, com.Childid, com.Name from table1 mem inner join table2 cd on mem.column1=cd.column1 inner join table3 com on com.childid = mem.childid where Parentid is NULL UNION SELECT com.Parentid, com.Childid,com.Name from table1 mem inner join table3 com on com.childid = mem.childid inner join table2 cd on mem.column1=cd.column1 where Parentid is NOT NULL) a group by Parentid, Childid;"; 

       Cursor cdata = myDbHelper.getView(sql);

and the List Adapter is:

 private static final String fields[] = {"Name"}; 
 int[] names = new int[] {R.id.name};

 SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this,R.layout.clientlist1, cdata, fields,names );

and the clientlist.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_alignParentRight="true" 
           android:layout_width="fill_parent"   
           android:layout_height="wrap_content" 
           android:textSize="12sp"
           android:textColor="#104082"
           android:textStyle="bold"
           android:layout_weight="1" />  

From this i am getting the list having the complete list having both parent and child list items in a single list view. I wish to differ in their text style(bold, normal) for parent and child items respectively. Please help me with the code/links. Thanks a lot in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about android