i have a list view and i want to mimic the functionality of UITableViewEditingStyle in iphone . I want the listview to have a delete button and when the user clicks the deleting button, that particular ro开发者_开发问答w should get deleted not only from the database but also from the listview.
I am using ListActivity.
Thank you for your help.
Here is the code that i am using
import android.R.anim; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.SimpleAdapter; import android.widget.SimpleCursorAdapter;
public class EditSiteList extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.editsitelist);
HandleDatabase db = new HandleDatabase(null,null,null);
String names[] = db.getSites();
ListAdapter la = new Arraydapter(this,R.layout.editsiterow,R.id.sitename,names);
HandleDatabase hd = new HandleDatabase(null, null, null);
hd.getSitesCursor(), new String[]{"name"}, android.R.id.);
setListAdapter(la);
}
You have to implement your own ListAdapter
with this functionality plus you have to decide where to situate the Delete button. At least I did so in my project when I had found that Android has no equivalents of this iPhone feature. In your ListAdapter
you should delete the items from the ListView
and from the DB manually.
精彩评论