开发者

Display dropdown on click of image in android

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开发者_如何学Go 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:)


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;
  }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜