0

I have the following code in a tabbed Fragment:

    private SetRowsCustomAdapter adapter;
private ArrayList<SetRows> rowsArray = new ArrayList<SetRows>();

    for (Map.Entry<String, String> current_file:filesInFolder.entrySet()) {
     rowsArray.add(new SetRows(R.drawable.ic_launcher, current_file.getKey().toString(), current_file.getValue().toString()));
        }
         adapter = new SetRowsCustomAdapter(getActivity(), R.layout.customlist, rowsArray);
     dataList = (ListView) mFrame3.findViewById(R.id.lvFiles);
     dataList.setAdapter(adapter);
     }

getActivity().deleteFile(txt + ".trp");
adapter.remove(adapter.getItem(info.position));
adapter.notifyDataSetChanged();
startActivity(new Intent(getActivity(), MainActivity.class).putExtra("tab", 2));

which deletes a row within my ListView and starts a new activity to show the changes. Although I have the adapter.notifyDataSetChanged(), it doesn't display the changes once a row is deleted without the last line on the code above.

Can someone please help me fix that so it shows the changes without starting a new activity.

Si8
  • 9,141
  • 22
  • 109
  • 221
  • you don't need the notifyDataSetChanged. – njzk2 Dec 02 '13 at 21:44
  • I removed the last two lines but my ListView does not update unless I go out of the tab and come back to it again. – Si8 Dec 02 '13 at 21:45
  • are you sure this adapter is the adapter for the list being viewed? – njzk2 Dec 02 '13 at 21:47
  • I updated the above code with more info. I am pretty sure it is. – Si8 Dec 02 '13 at 21:50
  • what is funny is that when you reload the page it updates. it means the filesInfolder map is also updated. – njzk2 Dec 02 '13 at 21:56
  • Any idea how to do it without reloading the Fragment activity? – Si8 Dec 02 '13 at 21:58
  • from your code, reloading should restore the original state, unless there is something else you are doing. – njzk2 Dec 02 '13 at 21:59
  • It reloads the activity, so when I press the Back button it goes back to the old activity again. – Si8 Dec 02 '13 at 22:00
  • what i mean is, if you don't change the content of filesInFolder, there is no reason why reloading the view should display anything else but what is in filesInFolder. – njzk2 Dec 02 '13 at 22:24

1 Answers1

0

Use of custom adapter is better for it, these link will help you for it Remove ListView items in Android How to remove arraylist item and then update listview

I think you require to delete from arraylist then call adapter setNotifyDataChange(), b'cos when you call this function it reload the adapter from arraylist.

Community
  • 1
  • 1
Android Leo
  • 666
  • 1
  • 8
  • 24