Thursday, December 16, 2010

[android-developers] Re: how to change child list color in ExpandableList

Here my class in extends from ExpandableListActivity. therefore I have
implemnts ExpandableListAdapter and override getChildView(int
groupPosition, int childPosition, boolean isLastChild, View
convertView, ViewGroup parent).

But when I from where should I call this method and what parameter
should I pass at the time of calling this method. My code is like:

SQLiteDatabase sampleDB = null;
String SAMPLE_DBNAME = "NewHomeAutoDataBase";
String ROOM_TABLE_NAME = "RoomTable";
String SWITCH_TABLE_NAME = "SwitchTable";
int idVal;

private ExpandableListAdapter mAdapter;


@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME,
MODE_PRIVATE, null);

Cursor groupCursor = sampleDB.rawQuery ("SELECT _id,
RoomName ,SwitchFullName FROM SwitchTable GROUP BY RoomName",null);
System.out.println ("#######"+groupCursor.getCount());
System.out.println ("_____"+groupCursor.getPosition());
System.out.println (groupCursor.getColumnIndex("RoomName"));
groupCursor.getColumnIndexOrThrow("_id");

// Set up our adapter
mAdapter = new MyExpandableListAdapter(groupCursor,
this,
android.R.layout.simple_expandable_list_item_1,
android.R.layout.simple_expandable_list_item_2,
new String[] {"RoomName"}, // Name for group layouts
new int[] {android.R.id.text1},
new String[] {"SwitchFullName"}, // Number for child
layouts
new int[] {android.R.id.text1});

setListAdapter(mAdapter);

System.out.println ("%%%%
%"+getExpandableListAdapter().getGroupCount());
System.out.println ("::::::::::::::"+this.getSelectedId());
//getChildView();where should I call this and how parameter
pass to this?

}

@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{


View v = getChildView(groupPosition, childPosition, isLastChild,
convertView, parent);

return v;

}

@Override
public void onGroupExpand(int groupPosition)
{
System.out.println ("Inside onGroupExpand~~~~");
// TODO Auto-generated method stub
super.onGroupExpand(groupPosition);
idVal = groupPosition;
System.out.println ("``````````````");
// System.out.println ("``````````````"+getString(groupPosition));

Toast.makeText(this, "Group Clicked on pos = "+ groupPosition,
Toast.LENGTH_SHORT).show();

}


public class MyExpandableListAdapter extends
SimpleCursorTreeAdapter
{

public MyExpandableListAdapter(Cursor cursor, Context context,
int groupLayout,
int childLayout, String[] groupFrom, int[] groupTo,
String[] childrenFrom,
int[] childrenTo){
super(context, cursor, groupLayout, groupFrom, groupTo,
childLayout, childrenFrom,
childrenTo);
}

@Override
protected Cursor getChildrenCursor(Cursor groupCursor)
{
System.out.println ("Inside getChildrenCursor");
String roomname =
groupCursor.getString(groupCursor.getColumnIndex("RoomName"));
System.out.println ("@@#@#@#@#"+idVal);
Cursor groupCursor1 = sampleDB.rawQuery ("SELECT
_id,SwitchFullName FROM SwitchTable where RoomName='"+roomname
+"'",null);

return groupCursor1;
}

}

On Dec 17, 8:28 am, "pramod.deore" <deore.pramo...@gmail.com> wrote:
> TreKing, Thanks for quick response.
>
> On Dec 17, 8:11 am, TreKing <treking...@gmail.com> wrote:
>
> > On Thu, Dec 16, 2010 at 9:00 PM, pramod.deore <deore.pramo...@gmail.com>wrote:
>
> > > TreKing, Thanks .Normally we do this by changing in xml file but here there
> > > is no xml file. so how to do this.
>
> > Oh, durf - didn't read closely enough.
>
> > Well then, try overriding getChildeView and getGroupView, calling super to
> > do the work, get the returned View, change the properties on it, then return
> > it.
>
> > -------------------------------------------------------------------------------------------------
> > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> > transit tracking app for Android-powered devices
>
>

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment