Как удалить элемент из моего пользовательского базового адаптера?

Я расширяю Baseadapter, чтобы сделать пользовательскую строку ListView. У меня есть контекстное меню, которое открывает каждый раз, когда пользователь удерживает ряд и подсказывает, если он хочет удалить его. Однако как удалить ряд? Hashmap - это только тестовые данные.

private MyListAdapter myListAdapter;
private ArrayList<HashMap<String, String>> items;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    items = new ArrayList<HashMap<String,String>>();
    HashMap<String, String> map1 = new HashMap<String, String>();
    map1.put("date", "10/09/2011");
    map1.put("distance", "309 km");
    map1.put("duration", "1t 45min");
    items.add(map1);

    myListAdapter = new MyListAdapter(this, items);
    setListAdapter(myListAdapter);
    getListView().setOnCreateContextMenuListener(this);
}


private class MyListAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<HashMap<String, String>> items;

    public MyListAdapter(Context context, ArrayList<HashMap<String, String>> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = convertView;

        if (view == null) {
            LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.row_log, null);
        }

        TextView rowLogOverview = (TextView) view.findViewById(R.id.rowLogOverview);

        HashMap<String, String> item = items.get(position);
        rowLogOverview.setText(item.get("date"));

        return view;
    }
}
8
задан SBerg413 14 November 2013 в 02:02
поделиться