[英]How to add checkbox on all the listView items after having a long item click? Android Java
我想在我的項目中添加一個功能,如果用戶單擊 listView 上的項目之一,則會出現一個復選框,允許用戶一次刪除 1 個或多個項目。 當你想刪除筆記和/或文件夾等時,類似於三星筆記。但是,這個概念對我來說是完全陌生的,目前,我不知道從哪里開始或者我應該看什么主題/資源/示例代碼為了。 此外,我有一個自定義數組適配器類,我曾經訂購它來使用我的 ListView,但據我所知,您只需要 1 個數組適配器類即可完成這項工作,這讓我感到困惑,因為我不知道從哪里開始進一步操縱它。 任何幫助都會很棒!
這是我目前擁有的陣列適配器
//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;
}
}```
在 R.layout.folder_view 中添加一個並使其不可見或消失。 OnLongClick 使它們可見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.