android - 在 Ionic 中实现多选功能(长按/按住并选择)

标签 android angular ionic-framework multi-select long-press

我正在做一个有列表的 Ionic 项目。我想要一个多选功能就像 android gallery 中的按住和选择功能,这样长按复选框就会出现在列表项的前面,使我能够选择多个项目。

关于如何实现它有什么建议吗?我不是在寻找 GalleryView 功能,只是长按并选择功能,就像它一样。

是否可以不创建实际的复选框?或者我是否需要创建复选框并实现暂停事件?

注意:对我是否要实现android gallery功能感到困惑的 friend 请注意!我不想在这里实现 android gallery 功能。我只想在简单列表上实现多选功能,就像我们在 android 画廊中长按选择多张图片一样,甚至举个例子,在联系人列表中选择多个联系人等。

最佳答案

试试这个 -

<ion-header>
<ion-navbar color="primary">
<ion-title>Notifications</ion-title>
<ion-buttons end *ngIf=selection>
  <button ion-button tappable (click)=disableSelect()>
    <ion-icon name="close" style="zoom:1.5;"></ion-icon>
  </button>
  </ion-buttons>
 </ion-navbar>
</ion-header>

<ion-content padding>
 <div *ngFor="let notification of notifications; let i=index" tappable text-wrap (click)=!selection?toggleGroup(i):selectItem(i,notification)
 (press)=selectItem(i,notification) [ngStyle]="{'background-color': notification.isSelected ? '#f2f2f2' : '#ffffff'}">
 </div>
</ion-content>

typescript

export class NotificationPage {
notifications = new Array<Notification>();
selection: boolean = false;

constructor() {}

public selectItem(index: number, notification: Notification) {
   this.selection = true;
   notification.isSelected = !notification.isSelected;
   this.notifications[index] = notification;
 }

public unselectAll() {
   this.selection = false;
   this.notifications.forEach(notification => {
     notification.isSelected = false;
   });
  }
}

我使用了两个变量,第一个在名为 isSelected 的模型类中。其目的是确定是否选择了特定项目。此外,项目样式是使用基于相同标志的 [NgStyle] 完成的。其次是在名为 selected 的页面中。其目的是在选择项目后对 UI 进行必要的更改。

关于android - 在 Ionic 中实现多选功能(长按/按住并选择),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50187097/

相关文章:

java - React Native : error: cannot find symbol > new AppCenterReactNativeAnalyticsPackage(MainApplication. 这个

typescript - 如何将来自 http.get 的响应映射到 Angular 2 中类型化对象的新实例

html - 在折叠状态下显示 rss 提要中的前几项

node.js - cloud-Angular 没有导出成员 ProvideCloud

选择 Spinner 时,Android Scrollview 更改位置(向下滚动)

java - 如何动态获取edittext的值?

Android 未知主机异常

javascript - 模拟测试 http - angular2

Angular Elements 没有正确包含 Material Theme css

javascript - Google Maps JavaScript API 可在浏览器中使用,但无法在设备上的 Cordova 应用程序中使用