开发者

How to delete entry and video file in a listview file browser?

开发者 https://www.devze.com 2023-03-06 02:32 出处:网络
Problem description: I wanted a \"delete\" functio开发者_开发技巧n which could perform delete/remove of the selected entry in a listview and at the same time delete the residing video file string in t

Problem description: I wanted a "delete" functio开发者_开发技巧n which could perform delete/remove of the selected entry in a listview and at the same time delete the residing video file string in the Video_List directory then it refresh the content of the listview?

I'm rather new in android/java can someone help me with it? Do scroll down to evaluate the problem i'm facing please!! Can someone tell me what is the specific code i should add into my current codes to perform the above mention function??


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 = new ListViewAdapter(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!


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);


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.


@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;}
    ////////////////
0

精彩评论

暂无评论...
验证码 换一张
取 消