I'm creating an expandable listview that contains a restaurant menu. When the user clicks on one of the items, he sees the details of the item (for example clicking on the row "avocado roll" shows a new layout that states "avocado, crab, rice").
Here is a screenshot of what a standard view is:
(I can't post photos because I am new but here is what the user would see if he saw the listview:
PRODUCT DESCRIPTION
PRODUCT DESCRIPTION
PRODUCT DETAIL (different format)
PRODUCT DESCRIPTION
PRODUCT DESCRIPTION
The idea is that the default features the name of the food item; and if the user clicks (or swipes, eventually - but let's keep it simple for now) he should see the description (in black).. Problem is, when I scroll the black row switches back to the original default format. (the problem will become more acute when I try to get the interface to "remember" where the user clicked and keep those buttons pressed so teh user can know what he ordered - and it clearly has to do with me not understanding how the holder works!)
I use a viewflipper inside each row and it's working great - fast and reliable. Also only a single row gets selected when I click, which is nice.
My only problem is I can't get the holder to remember the status of the viewflipper when I scroll. So it resets every time I scroll.
For example, in the steak example, if I show the detail view in the row, then scroll down and back up, the view in the row returns to the name "avocado roll". Clearly I'm not implementing the holder correctly so it remembers the viewflipper value but for the life of me I can't figure this out after 24 hours of trying!
Here is my adapter code:
ExpandMenu Adapter so you know what the lists are referring to:
public ExpandMenuAdapter(Context passedContext, ArrayList<ExpandOptionsGroup> passedGroupList){
this.context = passedContext;
this.groupList = passedGroupList;
}
getChildView code: this is where I think the holder issue is but I can't ID it!
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View rowView = null;
String[] child = getChild(groupPosition, childPosition);
if (rowView == null){
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
rowView = infalInflater.inflate(R.layout.item_row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.itemName = (TextView) rowView.findViewById(R.id.tvItem);
viewHolder.itemPrice = (TextView) rowView.findViewById(R.id.tvPrice);
viewHolder.itemDetail = (TextView) rowView.findViewById(R.id.tvDetail);
viewHolder.itemLayout = (LinearLayout) rowView.findViewById(R.id.item_layout);
viewHolder.rowFlipper = (ViewFlipper) rowView.findViewById(R.id.item_row_flipper);
viewHolder.itemLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
viewHolder.rowFlipper.showNext();
Toast.makeText(context, "You clicked", Toast.LENGTH_SHORT).show();
}
});
rowView.setTag(viewHolder);
viewHolder.rowFlipper.setTag(groupList.get(groupPosition));
}else{
rowView = convertView;
((ViewHolder) rowView.getTag()).rowFlipper.setTag(groupList.get(groupPosition));
}
ViewHolder holder = (ViewHolder) rowView.getTag();
//holder.rowFlipper.set(groupList.get(groupPosition)); CLEARLY THIS IS WRONG
holder.itemName.setText(child[MenuXMLGettersSetters.ELEMENT_NAME]);
holder.itemDetail.setText(child[MenuXMLGettersSetters.ELEMENT_DETAIL]);
if(!child[MenuXMLGettersSetters.ELEMENT_PRICE].isEmpty()){
holder.itemPrice.setText("$"+child[MenuXMLGettersSetters.ELEMENT_PRICE]);
}else{
holder.itemPrice.setText("");
}
return rowView;
}
private static class ViewHolder {
public TextView itemName;
public TextView itemPrice;
public TextView itemDetail;
public LinearLayout itemLayout;
public ViewFlipper rowFlipper;
private void getViewHolderDetail(){
itemDetail.isShown();
}
}