i have a problem. Help me please. I have activity with viewpager. See code:
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>
Not work:
String childFrom[] = new String[] {"imagePath", "subCatName"};
int childTo[] = new int[] {R.id.cardImage, R.id.textChild};
Work:
String childFrom[] = new String[] {"subCatName"};
int childTo[] = new int[] {R.id.textChild};
With ImageView i have error: “imageView cannot be cast to android.widget.textview”.
Sorry for my english ! Thanks a lot in advance!
You need to extend your SimpleExpandableListAdapter as they expect TexViews
http://developer.android.com/reference/android/widget/SimpleExpandableListAdapter.html
have a look at similar solution
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/J4H9332aQp4