简体   繁体   English

单击长项目后如何在所有 listView 项目上添加复选框? 安卓Java

[英]How to add checkbox on all the listView items after having a long item click? Android Java

I want to add a feature on my project where if the user clicks one of the items on the listView then a checkbox would appear allowing the user to delete 1 or many items at once.我想在我的项目中添加一个功能,如果用户单击 listView 上的项目之一,则会出现一个复选框,允许用户一次删除 1 个或多个项目。 Similar to Samsung Notes when you want to delete notes and or folders, etc. However, this concept is completely foreign to me and currently, I don't know where to begin to start this or what topic/resource/sample code I should look for.当你想删除笔记和/或文件夹等时,类似于三星笔记。但是,这个概念对我来说是完全陌生的,目前,我不知道从哪里开始或者我应该看什么主题/资源/示例代码为了。 Also, I have a custom Array Adapter class that I used to order to work with my ListView but it came to my knowledge that you only need 1 array adapter class to make this work which made me confused since I don't know where to begin to manipulate it even further.此外,我有一个自定义数组适配器类,我曾经订购它来使用我的 ListView,但据我所知,您只需要 1 个数组适配器类即可完成这项工作,这让我感到困惑,因为我不知道从哪里开始进一步操纵它。 Any help would be amazing!任何帮助都会很棒!

Here is my Array Adapter that I have at the moment这是我目前拥有的阵列适配器

//want to create our own custom ArrayAdapter. Going to extends the base class ArrayAdapter and hold our
//Word object
public class WordAdapter extends ArrayAdapter<WordFolder> {
    //constructor - it takes the context and the list of words
    WordAdapter(Context context, ArrayList<WordFolder> word){
        super(context, 0, word);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        View listItemView = convertView;
        if(listItemView == null){
            listItemView = LayoutInflater.from(getContext()).inflate(R.layout.folder_view, parent, false);
        }

        //Getting the current word
        WordFolder currentWord = getItem(position);
        //making the 3 text view to match our word_folder.xml
        TextView date_created = (TextView) listItemView.findViewById(R.id.date_created);

        TextView title = (TextView) listItemView.findViewById(R.id.title);

        TextView desc = (TextView) listItemView.findViewById(R.id.desc);

        //using the setText to get the text and set it in the textView
        date_created.setText(currentWord.getDateCreated());

        title.setText(currentWord.getTitle());

        desc.setText(currentWord.getTitleDesc());

        return listItemView;

    }

}```  

In R.layout.folder_view add one and make it invisible or gone.在 R.layout.folder_view 中添加一个并使其不可见或消失。 OnLongClick make them Visible. OnLongClick 使它们可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将复选框添加到列表视图中的每个项目 - How to add checkbox to each item in listview 长时间在Android错误中从列表视图删除项目 - Deleting item from listview by long click in Android error 将点击功能添加到所有应用程序ListView Android - Add click function to all apps listview android 如何在按钮单击事件上将项目添加到列表视图? - How to add an item to a listview on a button click event? 如何将点击添加到listView中的特定项目 - How to add click to specific item in listView 如何实现Android Recyclerview项目单击和复选框项目单击? - How to implement Android Recyclerview item click AND checkbox item click? 如何在没有长单击事件的情况下在 Android 中触发上下文操作栏 (CAB) 以便从 Android 中的 ListView 中选择多个项目 - How to trigger contextual action bar (CAB) in Android without long-click event in order to select multiple items from ListView in Android 在Android中长按一个项目时,如何更改所有RecyclerView项目的可见性? - How to change the visibility of all RecyclerView items when a single item is long clicked in Android? Android,如何动态更新 ListView 项和所有后续项? - Android, how do I dynamically update a ListView item and all subsequent items? 将项目添加到ListView - Android - Add Items to ListView - Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM