/**
* listview总数
*/
@Override
public int getCount() {
return houses.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView tv = new TextView(getApplicationContext());
tv.setTextSize(20);
tv.setTextColor(Color.BLUE);
house house = houses.get(position);
tv.setText(house.toString());
return tv;
}
}
// 长按时显示的菜单
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("请选择操作");
menu.add(0, ITEM_MODIFY, 0, "编辑");
menu.add(0, ITEM_DELETE, 1, "删除");
}
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
int index = (int)info.id;
// Object itemValue = adapter.getItem(info.position);
switch (item.getItemId()) {
case ITEM_MODIFY:
break;
case ITEM_DELETE:
String[] str = {String.valueOf(index)};
db= (new RentingDB (getApplicationContext())).getWritableDatabase();
db.delete("house","RecNo=?",str);
cursor.requery();
I hope someone strong enough to solve my problem.If some problem on understanding my request , please make a comment on me . I will response as soon as possible