Android系统。 ImageView无法强制转换为android.widget.textview

时间:2013-01-24 13:04:16

标签: android imageview expandablelistview

我有一个问题。请帮帮我。我有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”。

抱歉我的英文!非常感谢提前!

1 个答案:

答案 0 :(得分:2)