android - 从 RecyclerView 中“隐藏”项目
问题描述
从 RecyclerView 中“隐藏”一个项目。移除一个项目,但允许用户将其取回。用户必须能够将所有已移除的项目取回。对此采取不同的方法。
上面的链接是列表的屏幕截图。我希望能够从列表中隐藏一个项目(如上图所示),但仍然允许用户将所有隐藏的项目带回列表中。
用于填充列表的代码。
//Method used to retrieve all installed applications
private ArrayList<AppData> getInstalledPackages() {
List<String> appsList = new ArrayList<>();
ArrayList<AppData> appDataArrayList = new ArrayList<AppData>();
AppInfoExtractor apkInfoExtractor = new AppInfoExtractor(this);
appsList = apkInfoExtractor.GetAllInstalledApkInfo();
if (appsList != null && appsList.size() > 0) {
for (int i = 0; i < appsList.size(); i++) {
AppData appData = new AppData();
appData.setAppName(apkInfoExtractor.GetAppName(appsList.get(i)));
appData.setPackageName(appsList.get(i));
Version version = new Version();
version.setVersionName(apkInfoExtractor.getVersionName(appsList.get(i)));
version.setVersionCode(apkInfoExtractor.getAppVersionCode(appsList.get(i)));
List<String> grantedPermissions = getPermissionsForPackage(appsList.get(i));
List<String> grantedPermissionsShort = getShortPermissionStrings(grantedPermissions);
version.setPermissions(grantedPermissionsShort);
ArrayList<Version> versions = new ArrayList<Version>();
versions.add(version);
appData.setVersions(versions);
appDataArrayList.add(appData);
}
}
return appDataArrayList;
}
列表适配器的代码。
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
AppInfoExtractor apkInfoExtractor = new AppInfoExtractor(context1);
final String ApplicationPackageName = (String) stringList.get(position);
final String ApplicationLabelName = apkInfoExtractor.GetAppName(ApplicationPackageName);
Drawable drawable = apkInfoExtractor.getAppIconByPackageName(ApplicationPackageName);
viewHolder.textView_App_Name.setText(ApplicationLabelName);
viewHolder.textView_App_Package_Name.setText(ApplicationPackageName);
viewHolder.tv_version_name.setText("Version Name: " + apkInfoExtractor.getVersionName(ApplicationPackageName));
viewHolder.tv_version_code.setText("Version Code: " + apkInfoExtractor.getAppVersionCode(ApplicationPackageName));
viewHolder.imageView.setImageDrawable(drawable);
//Adding click listener on CardView to open clicked application directly from here .
viewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent perm = new Intent(context1, AppDetailActivity.class);
perm.putExtra("PACKAGE_NAME", ApplicationPackageName);
perm.putExtra("APP_NAME", ApplicationLabelName);
context1.startActivity(perm);
}
});
}
解决方案
请参阅Recyclerview Swipe to remove以从中删除项目recyclerView
。
要取消隐藏所有项目,请添加一个带有“取消隐藏所有”选项的菜单选项。在列表中滑动时存储所有已删除的数据,并在选择“取消隐藏全部”菜单选项时
将其附加到数据中。recyclerView
希望能帮助到你。
推荐阅读
- java - 使用 for 循环嵌套下拉菜单会导致过时的元素引用错误
- c# - 如何在 C# 中执行通用 SQL 命令?
- rest - EnvelopeDefinition:EventNotification API 类型的基本身份验证
- ios - 在 XCODE 中使用 Distr 证书组装后,Iphone 无法安装我的应用程序
- java - 使用 Kotlin 属性访问语法设置 Java 字段是否安全
- arrays - 根据多个数组条件计算表中的行数
- javascript - 从ajax分配javascript类中的字段
- python - Mnist 与 Tensorflow Premade Estimator,评估时输入尺寸不匹配
- tensorflow - Keras layer.weights 和 layer.get_weights() 给出不同的值
- javascript - 查询 SELECT * AS 不工作