如何删除列表视图文件浏览器中的条目和视频文件?

发布于 2024-11-07 05:50:20 字数 176 浏览 4 评论 0原文

问题描述:我想要一个“删除”功能,它可以执行删除/删除列表视图中所选条目的操作,同时删除Video_List目录中驻留的视频文件字符串,然后刷新列表视图的内容?

我对 android/java 相当陌生,有人可以帮助我吗?请向下滚动以评估我面临的问题!有人可以告诉我我应该添加到当前代码中以执行上述功能的具体代码是什么吗?

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 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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寂寞清仓 2024-11-14 05:50:20

由于您已将选择存储到“item”对象中,因此在 deleteFile() 方法中,您需要从该对象检索文件路径,为此,请添加以下行:

模型.absolutePath =
mfile.getAbsolutePath();

在 getVideoFiles() 方法“for”循环中。

也在 onCreate 状态之前:

ListViewAdapter lv;

然后在 getVideoFiles 的最终状态:

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

最后在 deleteFile() 中你需要声明:

文件 myFile = new File(item.absolutePath);

lv.notifyDataSetChanged();

那应该可行!

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!

你好,陌生人 2024-11-14 05:50:20

您定义了 onListItemClick 覆盖,但从未调用此代码。您还应该将侦听器注册到您正在使用的视图。检查 android 如何处理用户界面事件

newListView.setOnItemClickListener(this);

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);
审判长 2024-11-14 05:50:20

您要删除适配器还是要删除列表中的行/条目?如果是后者,则更新 videoItems 并在适配器上调用 notificationDataSetChanged。如果您确实想删除适配器,只需将其设置为 NULL 或让它引用其他一些 ListAdapter 实例,GC 将处理其余的事情。

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.

鲜血染红嫁衣 2024-11-14 05:50:20
@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;}
    ////////////////
@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;}
    ////////////////
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文