在Android中使用Mvvmcross基于布局创建一个对话框

时间:2013-09-17 17:18:59

标签: android mvvmcross

很抱歉,如果这看起来如此简单,但是我查看了关于对话框的N + 1视频,它显示了在代码中创建对话框,而不是使用布局。

这就是我的所作所为:

ChangePasswordView.axml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="16dp">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <EditText
            android:id="@+id/oldpassword"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/YourOldPassword"
            android:inputType="textPassword"
            local:MvxBind="Text OldPassword" />
        <EditText
            android:id="@+id/newpassword"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:hint="@string/YourNewPassword"
            local:MvxBind="Text NewPassword" />
        <Button
            android:text="@string/ChangePassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            local:MvxBind="Click ChangePasswordCommand"
            android:paddingRight="42dp"
            android:paddingLeft="42dp" />
    </LinearLayout>
</FrameLayout>

ChangePasswordView.cs:

[Activity]
    public class ChangePasswordView : MvxDialogActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            DroidResources.Initialise(typeof(Resource.Layout));
            this.SetContentView(Resource.Layout.ChangePassword);
        }
        }

从视图模型中调用对话框的显示:

void ChangePassword()
{
  this.ShowViewModel<ChangePasswordViewModel>();
}

我也有Setup.cs:

public class Setup : MvxAndroidDialogSetup
{
 ...
}

运行导致错误抱怨:

Your content must have a ListView whose id attribute is 'android.R.id.list

1 个答案:

答案 0 :(得分:0)

我认为这里有一些关于“对话”是什么的混淆

对话1 - https://github.com/migueldeicaza/MonoTouch.Dialoghttps://github.com/kevinmcmahon/MonoDroid.Dialog

http://slodge.blogspot.co.uk/2013/05/n23-dialogs-n1-days-of-mvvmcross.html意义上的对话是基于MonoTouch.Dialog或MonoDroid.Dialog的'数据形式'。

这些是在代码中定义的 - 因为这就是MonoTouch.Dialog和MonoDroid.Dialog的含义。对于Droid,您可以覆盖显示的各个元素 - 每个元素都是从资源加载的 - 但是您无法将整个“活动”作为资源加载。

对话2 - http://developer.android.com/guide/topics/ui/dialogs.html

如果您不是在寻找MonoTouch.Dialog样式页面,而是在寻找Android原生弹出对话框,那么在MvvmCross中没有太多关于这些的内容。 https://github.com/slodge/MvvmCross-Tutorials/blob/master/Fragments/FragmentSample.UI.Droid/Views/HomeView.cs中有一个基于片段资源的对话框的示例,以及有关如何在MvvmCross Dialog中显示它们的一些有趣的最新讨论