MvvmCross Droid MvxListView 带有搜索 EditText?

2024-01-05

在 MvvmCross 中,是否可以有一个顶部带有搜索 EditText 的 Android MvxListView?如何?


在您的 View.axml 中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        local:MvxBind="Text SearchString" />
    <Mvx.MvxListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        local:MvxBind="ItemsSource FilteredList" />
</LinearLayout>

非常简单,EditText 是您的搜索查询框,其下方的列表本身将是您的过滤列表。

在您的 ViewModel.cs 中:

public class FirstViewModel 
        : MvxViewModel
    {
        public FirstViewModel()
        {
            _filteredList = _completeList;
        }


        private string _searchString;
        public string SearchString
        {
            get { return _searchString; }
            set
            {
                _searchString = value;
                if (string.IsNullOrEmpty(value))
                {
                    _filteredList = _completeList;
                }
                else
                {
                    _filteredList = _completeList.Where(o => o == value).ToList();
                }
                RaisePropertyChanged(() => SearchString);
                RaisePropertyChanged(() => FilteredList);
            }
        }


        private List<string> _completeList = new List<string>() { "a", "b", "c", "d", "e" };
        private List<string> _filteredList;
        public List<string> FilteredList
        {
            get { return _filteredList; }
        }
    }

这里的 ViewModel 从 EditText 接收 SearchString,然后使用 Linq 过滤完整列表。然后,它获取已过滤的列表和已过滤列表的 RaisesPropertyChanged。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MvvmCross Droid MvxListView 带有搜索 EditText? 的相关文章

  • 在我的 Android 应用程序中使用 ServerValue.TIMESTAMP

    我读过很多相关的 stackoverflow 问题 ServerValue TIMESTAMP 但我不知道如何在我的应用程序中使用它 我需要获取帖子创建的时间戳 时间戳应该添加到与帖子的 uid 作者等相同的位置 代码片段其中写这篇文章Fi
  • 如何在android网络库(ION)中使用自签名SSL?

    使用此网络库 https github com koush ion https github com koush ion 由于当前状态是开发 我想使用自签名 SSL 证书 图书馆论坛有一些讨论 https github com koush
  • 如何在 Android TextView 中使用土耳其语字符,如“ş ç ı ö”?

    我想在 android TextView 中写入 ile 但它没有正确绘制 怎样才能使用这样的字符呢 例如 我将文本视图设置为 ile 它显示为 ile 我怎样才能解决这个问题 尝试以下方法 看看是否有帮助 source http grou
  • android中根据屏幕尺寸计算图像尺寸

    我正在尝试根据屏幕尺寸计算图像高度和宽度 我从后端获取 5 x 7 尺寸的图像 为了将像素乘以 72 进行转换 我有 360 X 504 尺寸的图像 对于 360 X 504 我的动态透明矩形区域将显示为 1 223 x 1 179 即 8
  • 如何在Xamarin Forms中实现Google Auth登录?

    我是 Xamarin 新手 我希望使用 Xamarin Forms 在我的新应用程序中进行 Google 登录 正确的方法是什么 有更新的教程或视频来指导吗 从哪儿开始 thanks 除了link https developer xamar
  • 位图内存不足错误

    我对这个错误有疑问 我从 URL 制作网站图标解析器 我这样做是这样的 public class GrabIconsFromWebPage public static String replaceUrl String url StringB
  • 使用 HttpUrlConnection Android 将 base64 编码的图像发送到服务器

    我正在尝试使用 HttpUrlConnection 将 base64 编码的图像发送到服务器 我遇到的问题是大多数图像均已成功发送 但有些图像会生成 FileNotFound 异常 我的图像编码代码可以在下面找到 public static
  • 如何向开发人员发送崩溃报告?

    我开发 Android 应用程序 但在某些情况下我的应用程序force close 如果出现以下情况 我如何向开发人员发送包含详细信息的电子邮件force close随时发生 The ACRA https github com ACRA a
  • 在 Android Lollipop 中从 Uri 中裁剪照片后总是返回 Null?

    我尝试在拍照或挑选照片后从 Uri 中裁剪图像 我的代码是这样的 public static void cropImage Uri uri Activity activity int action code Intent intent ne
  • 我想从 android 中服务器的视频 url 创建缩略图

    My code public static Bitmap retriveVideoFrameFromVideo String videoPath throws Throwable Bitmap bitmap null MediaMetada
  • Android Fragment onCreateView 与手势

    我正在尝试在片段中使用手势 我在 FragmentActivity 中有以下内容来处理我的详细信息片段 我试图发生的情况是 当在视图上检测到滑动时 将该视图内的数据替换为上一个或下一个条目 如果有更好的方法来处理这个问题 我完全同意 然而
  • 如何从android中的外部存储中获取所选文件的文件路径?

    我在选择文件的文件路径时遇到问题 我搜索了整个堆栈溢出 但问题没有解决 从设备中选择文件的代码如下所示 Intent intent new Intent Intent ACTION GET CONTENT intent setType in
  • Android 时钟滴答数 [赫兹]

    关于 proc pid stat 中应用程序的总 CPU 使用率 https stackoverflow com questions 16726779 total cpu usage of an application from proc
  • 未解决的包含:“cocos2d.h” - Cocos2dx

    当我在 Eclipse 中导入 cocos2dx android 项目时 我的头文件上收到此警告 Unresolved inclusion cocos2d h 为什么是这样 它实际上困扰着我 该项目可以正确编译并运行 但我希望这种情况消失
  • 如何构建自定义摄像机应用程序?

    我正在尝试开发一个自定义摄像机录像机 当我的设备在 Activity 的 beginRecording 中执行 start MediaRecorder 方法时 应用程序崩溃 我不知道出了什么问题 因为我遵循谷歌API指南 http deve
  • 由于“进程崩溃”,仪器运行失败。

    我想运行以下测试 package com xxx yyy import android content Context import androidx test InstrumentationRegistry import androidx
  • 在android中创建SQLite数据库

    我想在我的应用程序中创建一个 SQLite 数据库 其中包含三个表 我将向表中添加数据并稍后使用它们 但我喜欢保留数据库 就好像第一次安装应用程序时它会检查数据库是否存在 如果存在则更新它 否则如果不存在则创建一个新数据库 此外 我正在制作
  • Android AdMob:addView 在返回活动之前不会显示广告

    我正在尝试在游戏顶部添加横幅广告 我的活动使用带有自定义 SurfaceView 的relativelayout 我希望广告与 SurfaceView 重叠 广告会加载并可点击 但不会绘制到屏幕上 当我离开活动并返回时 会绘制广告 例如 通
  • 使用 DataBindingComponent 的 Inflate 方法

    当 Glide 成功渲染图像后 我在更新文本视图时看到此错误 致命异常 java lang IllegalStateException 必需 CustomBinding 类中的 DataBindingComponent 为 null 绑定适
  • 使用Intent拨打电话需要权限吗?

    在我的一个应用程序中 我使用以下代码来拨打电话 Intent intent new Intent Intent ACTION CALL Uri parse startActivity intent 文档说我确实需要以下清单许可才能这样做

随机推荐