private List<String> locations_list =new ArrayList<String>();
public DataBase db;
public ListView lv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.locations);
db = new DataBase(getApplicationContext());
lv1=(ListView)findViewById(R.id.listView1);
this.load_list();
registerForContextMenu(lv1);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
public boolean onContextItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.set_property:
//startActivity(new Intent(locations.this, add_location.class));
return true;
case R.id.set_location:
return true;
case R.id.edit:
return true;
case R.id.delete:
db.location_delete(id); // will send id of the recored to be deletion as parameter
return true;
}
return false;
}
private void load_list(){
Cursor locations_list_db=db.location_result();
locations_list.clear();
while(locations_list_db.moveToNext()){
locations_list.add(locations_list_db.getString(locations_list_db.getColumnIndex("name")));
}
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , locations_list));
}
我在load_list()函数中从数据库加载数据到listview。 我想在onContextItemSelected()函数中将选定的子项从数据库中删除。 我该怎么做 我的英语很糟糕。对不起。