我有一個問題。請幫幫我。我有viewpager的活動。見代碼:Android。 ImageView無法投射到android.widget.textview
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「。
對不起,我的英語!提前感謝!
的形象圖不是一個文本視圖。 SimpleExpandableListAdapter通常需要文本 – njzk2
它按預期工作。你應該閱讀文檔 – Blackbelt
謝謝你的答案。你能幫我解決這個問題嗎? – Andrew