Under the first to describe the function I want to achieve, long press entry, select Delete, then you'll be prompted dialog, then click OK to delete the entry from the database, but also will be on view deleted
The relevant code
private SimpleAdapter restaurantListAdapter = null;
@ Override
protected void onResume () {
super.onResume ();
/ / Use simpleAdapter
restaurantListAdapter = new SimpleAdapter (this, getListForSimpleAdapter (), R.layout.restaurant_list_item,
new String [] {"restName", "Tel"}, new int [] {R.id.titleTextView, R.id.telTextView});
getListView () setTextFilterEnabled (true);.
getListView () setAdapter (restaurantListAdapter);.
Logger.d ("on ruseme");
}
getListForSimpleAdapter () method (return list)
private List
Delete button on the dialog listening
/ / Delete button to listen _____________________________ unfinished wrong (not refresh)
protected DialogInterface.OnClickListener deleteRestButtonListener () {
return new DialogInterface.OnClickListener () {
@ SuppressWarnings ("unchecked")
public void onClick (DialogInterface dialog, int id) {
MapmapRest = (Map ) restaurantListAdapter.getItem (positionOfItem);
positionId = (Long) mapRest.get ("restID");
deleteRestaurant (positionId);
String str = "The restaurant which restId (positionId) is" + positionId + "is deleted in Restaurant Table";
Logger.d (str);
getListForSimpleAdapter () remove (positionOfItem);.
Logger.d ("the size of list is" + getListForSimpleAdapter () size ().);
SimpleAdapter sa = (SimpleAdapter) getListView () getAdapter ();.
sa.notifyDataSetChanged ();
removeDialog (CONFIRM_DELETE_DIALOG) ;/ / clear the cache
}
};
}
But after running discovery, indeed, been deleted entries (can be found from the database), or retreat to re-enter the activity can be seen to be deleted
But when in operation (ie, the dialog click Delete) does not correspond to refresh the list,
How to solve it or where I wrote in error, please advice<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
notifyDataSetChanged () will go on to do UI refresh action, this action is best placed in the corresponding UI thread.
So try this:
In the main activity of the establishment of a handler, then the dialog inside sa.notifyDataSetChanged (); changed to send a message to actvity, call notifyDataSetChanged () in the handle of the process;
Reply:
Support
Reply:
I did not expect this issue to go before I try to thank
Reply:
Hello, I follow your approach changed, too successful, but still a little problem, look at the next part I modified it
/ / thread
private Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg) {
switch (msg.what) {
case REFRESH_LISTVIEW:
Logger.d ("call the handler to refresh listview");
/ * SimpleAdapter sa = (SimpleAdapter) getListView () getAdapter ();.
sa.notifyDataSetChanged (); * /
restaurantListAdapter = new SimpleAdapter (RestaurantList.this, getListForSimpleAdapter (), R.layout.restaurant_list_item,
new String [] {"restName", "Tel"}, new int [] {R.id.titleTextView, R.id.telTextView});
getListView () setTextFilterEnabled (true);.
getListView () setAdapter (restaurantListAdapter);.
break;
default:
Logger.d ("unknown message to handler");
break;
}
}
};
Delete button messaging section
Message message = new Message ();
message.what = REFRESH_LISTVIEW;
handler.sendMessage (message);
I am in the process of processing the message began to use the
SimpleAdapter sa = (SimpleAdapter) getListView () getAdapter ();.
sa.notifyDataSetChanged ()
That is commented out section, no effect
Later changed to have the effect of re-new the next
That notifyDataSetChanged this actually does not work ah this is why it is wrong or where I
Thank looked in trouble look
Reply:
Nobody responded, although the amount is not solved but notifyDataSetChanged () from the effect of ah
Reply:
This is the code you have written questions, getListForSimpleAdapter () each return a new object, that is, you remove one item at a time, remove the list is not your adapter used, so, of course, no notifydatachanged effect because originally list adapter used is not changed.
Reply:
Well you're right, thank you very much
Reply:
After the novice, learning, and heroes.
Reply:
Just encountered this problem, learning
Reply:
How it should be amended? ?
Reply:
FindViewById that control should need to hide / display on getView function if ... else ... outside judgment is refreshed every time that control
Reply:
Use list SimpleAdapter created by notifyDataSetChanged can not be updated because SimpleAdapter is mainly used to create a list of static data, if you want to achieve dynamic update data, you need to define yourself based on BaseAdapter the adapter, and then to update the list by notifyDataSetChanged.
No comments:
Post a Comment