Hello everyone!!! I'm new android, i'm trying to do with CursorTreeAdapter but it doesnt work. Please help!!!
Here is my code import android.app.Activity; import android.content.ContentUris; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.Contacts.People; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorTreeAdapter; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.TextView; public class ExpandableList extends Activity { private int mGroupIdColumnIndex; private String mPhoneNumberProjection[] = new String[] { People.Phones._ID, People.Phones.NUMBER }; private ExpandableListAdapter mAdapter; private LayoutInflater mInflater; private LayoutInflater mInflater_group; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.expandable_list); Cursor groupCursor = managedQuery(People.CONTENT_URI, new String[] {People._ID, People.NAME}, null,null,null); mGroupIdColumnIndex = groupCursor.getColumnIndexOrThrow(People._ID); ExpandableListView lv = (ExpandableListView) this.findViewById(R.id.expandable_list); MyExpandableListAdapter myAdapter = new MyExpandableListAdapter(groupCursor,this); lv.setAdapter(myAdapter); } public class MyExpandableListAdapter extends CursorTreeAdapter { public MyExpandableListAdapter(Cursor cursor, Context context) { super(cursor,context); } @Override protected Cursor getChildrenCursor(Cursor groupCursor) { Uri.Builder builder = People.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, groupCursor.getLong(mGroupIdColumnIndex)); builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY); Uri phoneNumbersUri = builder.build(); return managedQuery(phoneNumbersUri, mPhoneNumberProjection, null, null, null); } @Override protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) { TextView id = (TextView) view.findViewById(R.id.text1); id.setText(People.NUMBER); } @Override protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) { TextView id = (TextView) view.findViewById(R.id.text1); id.setText(People.NAME); } @Override protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) { mInflater = LayoutInflater.from(context); final View view = mInflater.inflate(R.layout.expandable_list_item_with_image, parent, false); return view; } @Override protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) { mInflater_group = LayoutInflater.from(context); final View view = mInflater_group.inflate(R.layout.expandable_list, parent, false); return view; } } } Here is my expandable_list.xml file <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ExpandableListView android:id="@+id/expandable_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"/> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" /> </LinearLayout> Here is my expandable_list_item_with_image.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" /> <ImageView android:id="@+id/icon" android:layout_width="35px" android:paddingLeft="2px" android:paddingRight="10px" android:paddingTop="2px" android:layout_height="30px" android:src="@drawable/icon"/> </LinearLayout> </RelativeLayout> Thanks in advance -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en