1

To make my question more understandable let me start with an image of my view.

enter image description here

I have an xml file named Menu, that has customized list view in it. I have created another xmlview named MenuCell as below.
enter image description here

Now tapping on add button I'm adding Item to the cart. which is working perfectly fine except not updating value of a cart (top right corner) on click event. But If I navigate to different view and come back to this view at this point I'm getting number of items added in the cart reflected properly. So How Can I reload my controllerview when I tap in my arradepter view's ImageButton.

this is my adapter code

holder.imageButton1.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                addItem(position);
                notifyDataSetChanged();
            }
        });

void addItem(int position) {

        count++;
        }

Where count is item added count.

If anyone can tell How am I able to reflect this count of my arrayadpter class to my other controller class that holds actual list view.

Any Help will be appreciated

Thanks in advance.

MayurCM
  • 701
  • 1
  • 14
  • 31

4 Answers4

0

Send the reference of your controller to your list adapter class. In the controller I guess you have a method that computes some data and after that call update the view that holds cart data summary. Just make sure that update is on UI thread.

gunar
  • 14,660
  • 7
  • 56
  • 87
0

You need to use callback feature to get notified to your activity , hence add button is part of list component so you can update your list view.

Here are few links for understanding of call back using interface

http://cleancodedevelopment-qualityseal.blogspot.in/2012/10/understanding-callbacks-with-java.html


http://stackoverflow.com/questions/11577695/what-is-a-call-back-interface-in-java
Shashank Agarwal
  • 512
  • 3
  • 12
0

After :
notifyDataSetChanged();
just add:
YourList.invalidateViews();
YourList.scrollBy(0, 0);

Dyna
  • 2,304
  • 1
  • 14
  • 25
0

Your List is not refreshing at the instant because you have to refresh data of your adapter and then call notifyDataSetChanged();

Suppose You have the data in an array which is visible in textview.Then In your function addItem add the data into ur array and then call notifyDataSetChanged(); This will immediately tell the list view that watever data it is containing is changed so time to refresh.

If you can paste more of ur adapter code i can be helpful

abc
  • 74
  • 9