Adapter modified in real time

Asked

Viewed 102 times

0

I have a Activity calling for ListaBasica and a Adapter by the name of adapterBasico. The Adapter contains a list of newsletters. A Activity contain information taken from Adapter as the sum of the time reported in the report.

My question is this: when I delete an item from Adapter I need the Activity be updated. I would like to know if there is any way to check if the Adapter has undergone some kind of change, as is the case with the EditText when using:

  EditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

There’s something like this to check the Adapter?

  • Edumachdo I don’t think anyone noticed your question. You want to know if there is an "Adapter changed Listener" or anything like that, right? If that’s it, what do you want it for? It’s just that usually you don’t need any of that, you can do that sort of thing when you remove the item from the List.

  • That’s exactly what I’m looking for @Jorgeb. As I said before I need to update the sum of the times of the newsletters, however as I am deleting the item directly by the Adapter, I can not change the Basic List, so I am looking for the "Adapter changed Listener"if it does not exist, I will find another way to update.

2 answers

1

After deleting the desired item, you should add the following line:

adapter.notifyDataSetChanged();

0

You can simply remove the desired item from the list using the method remove() of your ArrayAdapter. Where a possible way to do that would be:

Objeto item = arrayAdapter.getItem([INDEX]);
arrayAdapter.remove(item);

So then the way to modify the ArrayList and call notifyDataSetChanged() in the ArrayAdapter, which, by awakening consciousness, can first verify whether the arrayAdapter exists in this way:

if(arrayAdapter!=null){
    arrayList.remove([INDEX]);
    arrayAdapter.notifyDataSetChanged();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.