CursorTreeAdapter!!!

by beginner » Tue, 09 Feb 2010 01:42:51 GMT


Sponsored Links
 ello 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) {
mIn



Other Threads

1. How to add the animated GIF file as an UI element to android application?

Hi All,

   I want to add an animated GIF file as an UI element to the android
UI application.  Note that the GIF should be shown as animation but
not static image in the UI.

   Do you know how to do that?

   Thanks a lot!

Mingsky


--~--~---------~--~----~------------~-------~--~----~

2. How to start android emulator in landscape mode?

I find this thread about switching to landscape mode:

3. How to change font type say "Arial" of a TextView via xml layout properties...

4. Bug with alpha channel in sdk 1.5

5. The GIMP cannot digest the standard widget frames

6. embedded activities within Android 1.5

7. Positioning a view below another one inside a RelativeLayout via code