0

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();
    }
}
Laurent
  • 1,554
  • 19
  • 42
  • pls attach a screenshot for more understanding. Also as I can see you not modify rowFlipper state in getView method. – Georgy Gobozov Aug 04 '12 at 22:02
  • Hi @GeorgyGobonov, I could not post images but added text. Thanks for your response. What do you mean by "Modify Rowflipper state"? I tell it to "show next"; then I should also set the view it lands on as its current view? – Laurent Aug 04 '12 at 23:13
  • you can post your screenshots to external sites and give link here. – Georgy Gobozov Aug 06 '12 at 08:27
  • SOLVED IT.There were so many things wrong with the code... once that was fixed, I understood I needed to create a separate array every time the app opens, in order to store which buttons are clicked and which view was called for each. Tough 4 days but the payoff from getting it right on my own can't be beat. – Laurent Aug 07 '12 at 17:34

0 Answers0