长时间单击后如何在所有listView项上添加复选框? Android Java

问题描述

我想在项目中添加一个功能,如果用户单击listView上的一项,则将出现一个复选框,允许用户一次删除1个或多个项目。当您要删除便笺和/或文件夹等时,类似于Samsung Notes。但是,此概念对我来说是完全陌生的,目前,我不知道从何处开始此主题或我应该看什么主题/资源/示例代码对于。另外,我有一个自定义的Array Adapter类,用于订购ListView,但据我所知,您只需要1个array适配器类即可完成此工作,这使我感到困惑,因为我不知道从哪里开始。进一步操纵它。任何帮助都将是惊人的!

这是我目前拥有的阵列适配器

//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,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;

    }

}```  

解决方法

在R.layout.folder_view中添加一个,使其不可见或消失。 OnLongClick使它们可见。