Android List view refresh
-
I have one ListView which is showing me some data through an array (which is in another class and I'm accessing it through it's object). Whenever I delete an element from the ListView through context menu, the list is not refreshing but the element is deleted from the array. How can I refresh the list to show this? Code: public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (v.getId()==R.id.mainListView) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; post=info.position; menu.setHeaderTitle(stocks[info.position]); String[] menuItems = stt; for (int i = 0; i<menuItems.length; i++) { menu.add(Menu.NONE, i, i, menuItems[i]); } } } @Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); int menuItemIndex = item.getItemId(); String[] menuItems = stt; String menuItemName = menuItems[menuItemIndex]; listItemName = stocks[info.position]; stockname.remove(post-1); return true; }
-
Answer:
You have to notify your ListView adapter that the data has changed. listViewAdapater.notifyDataSetChanged(); If that for some reason doesnt work, and there are some wierd situations where it seems like it wasnt notifying, you can just reasing your adapter via the constructor with the updated array.
vivek_Android at Stack Overflow Visit the source
Related Q & A:
- How To View Hidden Facebook Friends List?Best solution by Yahoo! Answers
- How To View Facebook Private Friends List?Best solution by Yahoo! Answers
- How to implement search view for list view?Best solution by Stack Overflow
- How to refresh listview immediately in Android?Best solution by Stack Overflow
- How to add new view at the top of an existing view in Android?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.