I am trying to extend the BaseExpandableListAdapter, however, when I scroll through the list and I select one of the elements to expand, the list order is reversed. For example, if I have a list of 4 elements and select the 1st element, the order (top to bottom) will now be 4, 3, 2, 1 with the 4th element (now top). If I do not increase the 4th element, the order will return to 1, 2, 3, 4 without extended elements.
Here is my implementation:
public class SensorExpandableAdapter extends BaseExpandableListAdapter {
private static final int FILTER_POSITION = 0;
private static final int FUNCTION_POSITION = 1;
private static final int NUMBER_OF_CHILDREN = 2;
ArrayList<SensorType> mParentGroups;
private Context mContext;
private LayoutInflater mInflater;
public SensorExpandableAdapter(ArrayList<SensorType> parentGroup, Context context) {
mParentGroups = parentGroup;
mContext = context;
mInflater = LayoutInflater.from(mContext);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
if(childPosition == FILTER_POSITION) return "filter";
else return "function";
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView = (RelativeLayout)mInflater.inflate(R.layout.sensor_row_list_item, parent, false);
if(childPosition == FILTER_POSITION) {
((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setText("Add Filter");
} else {
((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setText("Add Function");
((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setEnabled(false);
}
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return NUMBER_OF_CHILDREN;
}
@Override
public Object getGroup(int groupPosition) {
return mParentGroups.get(groupPosition);
}
@Override
public int getGroupCount() {
return mParentGroups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView = mInflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false);
TextView tv = ((TextView)convertView.findViewById(android.R.id.text1));
tv.setText(mParentGroups.get(groupPosition).toString());
}
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
`
I just need to take a simple ArrayList of my own SensorType class. Children are the same for all classes, only two.
, LongClickable? ExpandableListActivity getExpandableListView().setOnLongClickableListener() ..., TextView OnLongClickableListener, .
!