2

我有个问题。请帮帮我。我有 viewpager 的活动。见代码:

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.cards);
    expListViewCategory = new ExpandableListView(mContext);
    SetListViewCategory();
    pages = new Vector<View>();
    pages.add(expListViewCategory);
    adapter = new CardsPagerAdapter(mContext, pages);
    pager = (ViewPager)findViewById( R.id.viewpager );
    pager.setAdapter(adapter);
}

private void SetListViewCategory()
    {
        groupData = new ArrayList<Map<String,String>>();
        childData = new ArrayList<ArrayList<Map<String, String>>>();

        String groupFrom[] = new String[] {"groupName"};
        int groupTo[] = new int[] {R.id.textGroup};

        String childFrom[] = new String[] {"imagePath", "subCatName"};
        int childTo[] = new int[] {R.id.cardImage, R.id.textChild};

        SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
                this,
                groupData, R.layout.group_view, groupFrom, groupTo,
                childData, R.layout.child_view, childFrom, childTo);

        expListViewCategory.setAdapter(adapter);

child_view.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:id="@+id/liner">

    <ImageView
          android:id="@+id/cardImage"
          android:layout_width="60dp"
          android:layout_height="40dp"
          android:layout_marginLeft="20dp"
          android:layout_marginTop="20dp"/>

    <TextView
         android:id="@+id/textChild"
         android:layout_width="wrap_content"
         android:layout_height="40dp"
         android:layout_marginLeft="20dp"
         android:layout_marginTop="20dp"
         android:textColor="@android:color/white" />

</LinearLayout>

不行:

String childFrom[] = new String[] {"imagePath", "subCatName"};
            int childTo[] = new int[] {R.id.cardImage, R.id.textChild};

工作:

String childFrom[] = new String[] {"subCatName"};
        int childTo[] = new int[] {R.id.textChild};

使用 ImageView 我有错误:“imageView 无法转换为 android.widget.textview”。

对不起我的英语不好 !提前非常感谢!

4

1 回答 1

2

您需要扩展您的 SimpleExpandableListAdapter,因为他们期望 TexViews http://developer.android.com/reference/android/widget/SimpleExpandableListAdapter.html

看看类似的解决方案 https://groups.google.com/forum/?fromgroups=#!topic/android-developers/J4H9332aQp4

于 2013-01-24T13:17:49.010 回答