Skip to content Skip to sidebar Skip to footer

How To Delete Entry And Video File In A Listview File Browser?

Problem description: I wanted a 'delete' function which could perform delete/remove of the selected entry in a listview and at the same time delete the residing video file string i

Solution 1:

Since you have stored your selection into "item" object then in deleteFile() method you need to retreive the file path from that object, for that to work add the line:

model.absolutePath = mfile.getAbsolutePath();

in getVideoFiles() method 'for' loop.

also before onCreate state:

ListViewAdapter lv;

then in getVideoFiles at the end state:

  lv = newListViewAdapter(this, R.layout.row, videoItems);
  setListAdapter(lv); 

finally in deleteFile() you need to state:

File myFile = new File(item.absolutePath);

lv.notifyDataSetChanged();

and that should work!

Solution 2:

You defined an override onListItemClick but this code is never been called. You should also register the a listener to the view you're using. Check how android handle user interface events.

newListView.setOnItemClickListener(this);

Solution 3:

Do you want to delete the adapter or do you want to delete a row/entry in the list? If latter, then update videoItems and call notifyDataSetChanged on your adapter. If you really want to delete the adapter, then just set it to NULL or have it refer to some other ListAdapter instance and the GC will take care of the rest.

Solution 4:

@Override // create contextuel menu 
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
                super.onCreateContextMenu(menu, v, menuInfo);
                menu.setHeaderTitle("Action");

                menu.add(0,100,1,"delete");

            }

    //////////////////////////////////////////////////
    @Override // Select an item 
        public boolean onContextItemSelected(MenuItem item) {
            final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
            switch(item.getItemId()){
            case 100:
    public void onClick(DialogInterface dialog, int id) {
                    db.delete_item(info.id);

                    //here update list view
    }
    });

    ////////////

    public boolean delete_item(long id){ 

    return db.delete("name_table", "_id="+id, null)>0;}
    ////////////////

Post a Comment for "How To Delete Entry And Video File In A Listview File Browser?"