public class ItemOptionsListAdapter extends BaseExpandableListAdapter {
private Context context;
private LayoutInflater inflater;
private List<String> categoryList;
public ItemOptionsListAdapter(Context context, List<String> categoryList) {
this.context = context;
this.categoryList = categoryList;
this.inflater = LayoutInflater.from(this.context);
}
private TextView title(View v, int resId, String text){
TextView tv = (TextView) v.findViewById(resId);
tv.setText(text);
return tv;
}
private ImageView image(View v, int resId, int icon){
ImageView iv = (ImageView) v.findViewById(resId);
return iv;
}
class ItemListViewHolder{
TextView title;
ImageView dropdownArrowImage;
}
@Override
public int getGroupCount() {
return categoryList.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return categoryList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return "size";
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 1;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
ItemListViewHolder categoryItemViewHolder;
if(convertView == null) {
convertView = inflater.inflate(R.layout.category_list_row_layout, null);
categoryItemViewHolder = new ItemListViewHolder();
convertView.setTag(categoryItemViewHolder);
}
else {
categoryItemViewHolder = (ItemListViewHolder) convertView.getTag();
}
categoryItemViewHolder.title = title(convertView, R.id.category_name_text, categoryList.get(groupPosition));
categoryItemViewHolder.dropdownArrowImage = image(convertView, R.id.dropdown_arrow_image, 0);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = inflater.inflate(R.layout.item_option_list_layout, null);
}
Log.d("child", " in getChildView()");
TextView itemPropertyTextView = (TextView)convertView.findViewById(R.id.item_option_property);
itemPropertyTextView.setText((String)"Size");
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
My child views are going to be static and each group is meant to contain a single child childlayout:
<?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:orientation="horizontal" >
<TextView android:id="@+id/item_option_property"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size" />
<RadioGroup android:id="@+id/item_option_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton android:text="Small"/>
<RadioButton android:text="Medium"/>
<RadioButton android:text="Large"/>
</RadioGroup>
</LinearLayout>
Group View layout:
<?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:orientation="horizontal"
android:background="#50ffffff" >
<TextView android:id="@+id/category_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="16sp"
android:layout_weight="1"
android:layout_margin="15dp"
android:textColor="#ffffff" />
<ImageView android:id="@+id/dropdown_arrow_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_arrow_down"
android:layout_margin="15dp"
android:rotation="270" />
</LinearLayout>
Also from logs, I know that the getChildView
never gets called
Thanks in advance
edit: I just noticed one thing, as soon as the groupView appears, a small scroll to its right flashes which gives an indication the all is working fine but the view itself isnt completely visible. But still dont seem to fix it.
My expandable list xml:
<ExpandableListView
android:id="@+id/item_option_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:groupIndicator="@null" >
</ExpandableListView>
Make sure you've clicked the group header, 'cause the children are collapsed by default.
Also, to be sure not having a problem of focusability, try to expand programmatically.
expandableListView.expandGroup(0);