Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a new item or updating existing item with notifydatasetchanged #98

Open
gdubs opened this issue Aug 19, 2016 · 3 comments
Open

Comments

@gdubs
Copy link

gdubs commented Aug 19, 2016

Hi there,
I've been struggling on how to properly update the current data with the fixed header. Whenever I would add an item, I would try to do the following:

So I can add a new string I started with a List<String[]> which I convert. I'm not sure if that's the right way but it seems to update the array String[][] with the updated data. My issue is it does not update the loaded table using notifyDataSetChanged as mentioned in this >> #29

public void addItem(Item item){
        if(item != null){
            items.add(item);

            String[] itemStrings = new String[5];
            itemStrings[0] = item.Id;
            itemStrings[1] = item.Description;
            itemStrings[2] = item.Quantity.toString();
            itemStrings[3] = item.UnitValue.toString();
            itemStrings[4] = item.Comment.Name;

            matrixGeneratedList.add(itemStrings);

            matrixGeneratedConverted = matrixGeneratedList.toArray(new String[matrixGeneratedList.size()][]);
        }
        matrixTableAdapter.notifyDataSetChanged();
    }

Also, what about on update?

Thank you!

@BraisGabin
Copy link
Collaborator

I can't know what's wrong in your code, this code can work. Any way, some tips:
Why do you use two different data structures with the same data? You can use the List<String[]> inside the adapter.
Don't change the adapter's data structure outside the adapter.
Don't call dataSetChanged from outside. The adapter must handle his own data and he must know when it must notify the changes.
I think that if you do this changes you will find the problem.

@gdubs
Copy link
Author

gdubs commented Aug 20, 2016

I think I found it. I had to refresh the data inside the adapter. I'm using the simple version so I call the setInformation. But I tend to call it outside of the adapter. So I'm guessing that's wrong? Or if it's right, should I call the datasetchanged inside that method after updating?

@nkVivek
Copy link

nkVivek commented Oct 13, 2017

I have same problem with it.
notifyDataSetChanged() method not working when Updating existing data in adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants