lundi 1 février 2016

How to delete items from listview created from SQLite using OnItemLongClickListener()?

I can't find an answer to delete in a listview created using SimpleCursorAdapter So i make this listview in a fragment, here's the code

final Cursor cursor = myDb.cautarevenituri();

    // The desired columns to be bound
    final String[] columns = new String[] {
            DatabaseHelper.COL_2,
            DatabaseHelper.COL_3
    };

    int[] toviewids = new int[] { R.id.nume_item,R.id.valoare_item};
    dataAdapter = new SimpleCursorAdapter(getActivity().getBaseContext(),R.layout.item_layout,cursor,columns,toviewids,0);
    //
    final ListView listView = (ListView)getView().findViewById(R.id.listView_venituri);

    listView.setAdapter(dataAdapter);
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                                       int position, long arg3) {
            Toast.makeText(getActivity(), " " + position, Toast.LENGTH_LONG).show();

            //delete from listview in database and listview too??
            //
            //

            return false;
        }

    });

Thank you.

Aucun commentaire:

Enregistrer un commentaire