小编Eug*_*kov的帖子

使用MvxCommand与CommandParameter绑定

我正在尝试使用带有CommandParameter的 fire MvxCommand,但遇到以下问题:MyView.axml包含:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        local:MvxBind="Click MyCommand, CommandParameter=foo" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2"
        local:MvxBind="Click MyCommand, CommandParameter=bar" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

MyViewModel.cs:

public class MyViewModel : MvxViewModel
{
    public ICommand MyCommand { get; private set; }

    public MyViewModel()
    {                                    // param is null
      MyCommand = new MvxCommand<string>(param =>
      {
          if (param == "foo")               
          {
            // do something
          }
          else if (param == "bar")
          {
            // do something else
          }
      });
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我检查param变量为 …

binding command mvvm xamarin.android mvvmcross

10
推荐指数
1
解决办法
9171
查看次数

使用MvvmCross从ViewModel显示AlertDialog

我使用MvvmCross创建我的Android应用程序,我面临以下问题:

当我试图显示在ViewModel中创建的AlertDialog时,

出现" 未处理的异常:Android.Views.WindowManagerBadTokenException ".

public class MyViewModel : MvxViewModel
{
    public ICommand ShowAlertCommand { get; private set; }

    public AuthorizationViewModel()
    {
        ShowAlertCommand = new MvxCommand(() =>
            {
                var adb = new AlertDialog.Builder(Application.Context); 
                adb.SetTitle("Title here");
                adb.SetMessage("Message here");  
                adb.SetIcon(Resource.Drawable.Icon);
                adb.SetPositiveButton("OK", (sender, args) => { /* some logic */});   
                adb.SetNegativeButton("Cancel", (sender, args) => { /* close alertDialog */});

                adb.Create().Show();
            });
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在研究时,我发现它是因为传递了对Context的引用而不是在AlertDialog.Builder中的Activity.

本主题中,我发现了以下决定:通过使用GetService()接收对当前Activity的引用,但我没有找到mvvmcross插件用于IMvxServiceConsumer,IMvxAndroidCurrentTopActivity接口.

我的问题是我可以从ViewModel显示AlertDialog吗?我怎样才能获得对Activity的引用,而不是Application.Context?什么是关闭AlertDialog的正确方法,用户将留在当前视图?

mvvm xamarin.android android-alertdialog mvvmcross xamarin

6
推荐指数
1
解决办法
8304
查看次数

Android:堆错误导入ShowcaseView作为项目,ClassNotFound导入为JAR,Out of Memory

我正在尝试将ShowcaseView引入我的Android项目.我从GitHub分叉了repo并尝试运行演示应用程序,但由于Java Heap错误而无法运行.

Unable to execute dex: Java heap space
Run Code Online (Sandbox Code Playgroud)

我试图增加Eclipse和RunConfiguration内存堆,但无法解决问题.我也没有几个月的Java堆空间错误,所以我想知道是否存在某种类型的循环产生过多的RAM请求.

由于导入项目不起作用,但构建确实有效,我尝试直接在项目的libs文件夹中导入ShowcaseView库JAR文件.我的项目运行但有一个

java.lang.NoClassDefFoundError: com.github.espiandev.showcaseview.R$styleable
Run Code Online (Sandbox Code Playgroud)

我能做什么?有没有人遇到过这种问题?我真的很喜欢这个库,并希望在我的项目中有这个功能,但是我对这个问题非常困惑: - /

先感谢您

java import android out-of-memory showcaseview

4
推荐指数
1
解决办法
1066
查看次数