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”。
抱歉我的英文!非常感谢提前!
答案 0 :(得分:2)
您需要扩展SimpleExpandableListAdapter,因为他们期望TexView http://developer.android.com/reference/android/widget/SimpleExpandableListAdapter.html
看看类似的解决方案 https://groups.google.com/forum/?fromgroups=#!topic/android-developers/J4H9332aQp4