tags:

views:

62

answers:

1

Hello

In my android application, i am displaying images of different categories.When i click on these images i would like to get a small list of the items in that particular category. What should i use for that.I am not sure which control will satisfy this and how can i use it.

Could any one please suggest me with a solution?

Please share your valuable suggestions.

Thanks in advance:)

A: 

Use ExpandableListView with a CursorAdapter. The group view can be your images and children can be the text.

Layout:

<?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/android:list"
  android:layout_width="fill_parent" android:layout_height="wrap_content" />
 <TextView android:id="@id/android:empty" android:layout_width="fill_parent" android:gravity="center"
  android:layout_height="wrap_content" android:text="Sorry, no data" />
</LinearLayout>

public class myListy extends ExpandableListActivity {

 Cursor mCursor;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  // Define group data in mCursor
  startManagingCursor(mCursor);

 ExpandableListView mExpandableListView = (ExpandableListView) findViewById(android.R.id.list);
  mExpandableListView.setGroupIndicator(null);

EAdapter adapter = new EAdapter(mCursor, getApplicationContext());
  mExpandableListView.setAdapter(adapter);
}

private class EAdapter extends CursorTreeAdapter {

  public EAdapter(Cursor cursor, Context context) {
   super(cursor, context);
  }

  @Override
  protected void bindChildView(View view, Context context, Cursor cursor,
    boolean isLastChild) {

   // Add your data to the child.

  }

  @Override
  protected void bindGroupView(View view, Context context, Cursor cursor,
    boolean isExpanded) {

   // Add your data to the group.

  }

  @Override
  protected View newChildView(Context context, Cursor cursor,
    boolean isLastChild, ViewGroup parent) {

   View view = getLayoutInflater().inflate(
     R.layout.text_layout, null);

   return view;
  }

  @Override
  protected View newGroupView(Context context, final Cursor cursor,
    boolean isExpanded, ViewGroup parent) {

                                View view = getLayoutInflater().inflate(
     R.layout.images_layout, null);

   return view;
  }

  @Override
  protected Cursor getChildrenCursor(Cursor groupCursor) {
                        // data for childern 

   return cursor;
  }
 }
Sameer Segal
Thanks Sameer.Could you please let me know how i can use it.Any sample code if you have :)
Remmyabhavan
Updated my answer!
Sameer Segal
Sameer if i use this expandable list the image should also be placed in the list.But what i am looking for is like i am placing images in a row on top of videoplayer.
Remmyabhavan
To be more clear i have images for different serials on top of videoplayer.If the user clicks on any of the images the sublist forthat image should be visible in the same page just below the image
Remmyabhavan
Any how Thanks Sameer for you response
Remmyabhavan
Use gallery for the top images. Create a PopWindow with list in it
Sameer Segal