I wrote a similar memo application, after adding the memorandum, will be on display listView row. Click each memo memorandum to the appropriate settings interface is used to locate the position listView the corresponding data in the database id. Among features a delete function to delete memo currently being edited, by calling the delete method passed in id. But I found that in order to delete only began deleted from the latest memo added, you can delete all finished, if a start is removed from the arbitrary, this memo after the click will string to another memo data. Finally, there will certainly be in a memo to delete the listView can not afford (position and id have been out of touch). How can I delete without affecting the normal function of any other list of? Here is the relevant code:
/ / add an event listener for the ListView
listView.setOnItemClickListener (new OnItemClickListener () {
@ Override
public void onItemClick (AdapterView av, View v, int positiong,
long id) {
/ / TODO Auto-generated method stub
/ / ListView's position by positioning database ID
Uri uri = ContentUris.withAppendedId (Tasks.CONTENT_URI, id +1);
Cursor cursor = managedQuery (uri, PROJECTION, null, null
, Tasks.DEFAULT_SORT_ORDER);
/ / Send relevant content
memorandum to the user interface sectionif (cursor.moveToNext ()) {
int id1 = cursor.getInt (0);
String content = cursor.getString (1);
String created = cursor.getString (2);
int alarm = cursor.getInt (3);
String date1 = cursor.getString (4);
String time1 = cursor.getString (5);
int on_off = cursor.getInt (6);
Bundle b = new Bundle ();
b.putInt ("id", id1);
b.putString ("content", content);
b.putString ("created", created);
b.putInt ("alarm", alarm);
b.putString ("date1", date1);
b.putString ("time1", time1);
b.putInt ("on_off", on_off);
Log.v ("--- time and date ---", date1 + "/" + time1);
intent.putExtra ("b", b);
intent.setClass (DiaryActivity.this, WriteDiaryActivity.class);
startActivityForResult (intent, NOT_NEW);
Log.v ("---- DiaryActivity ----", "open save original content");
}
}
});
Here is the relevant code function delete (delete function implemented on the button at the operator interface specific memo data)
deleteBn.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View arg0) {
/ / TODO Auto-generated method stub
/ / Receive data transmitted from the above
interfaceIntent intent = getIntent ();
if (intent! = null) {
Bundle b = intent.getBundleExtra ("b");
if (b! = null) {
int id = b.getInt ("id");
Uri uri = ContentUris.withAppendedId (Tasks.CONTENT_URI, id);
getContentResolver () delete (uri, null, null);.
finish ();
} Else
/ / Display an error dialog
showSaveErrorDialog (DELETE_ERROR);
}
}
}); Consult the relevant great God, how to achieve? Thank you! ! !
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
When adding data to listview add a map.put in list ("id", "1"); instance id is 1, in the event you can listen listview using id = (Integer) list.get (position). get ("id"); piece of data to the id is clicked
Reply:
Thank you, and I was handling this the same way as.
No comments:
Post a Comment