android - 适用于 Android 的 MVVM Activity Intent

标签 android mvvm

我正在尝试适用于 Android 的 MVVM。
我有一个按钮可以打开另一个 Activity onClick。
以下代码:

看法:

    <LinearLayout
            android:id="@+id/activity_test"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".mvvm.view.TestActivity">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Activity"
            android:onClick="@{viewModel.onClickButton1}"/>

    </LinearLayout>

View 模型:
public View.OnClickListener onClickButton1() {
    return view -> {
        mContext.startActivity(new Intent(mContext, MockActivity.class));
    };
}

这似乎对我不起作用。当我单击按钮时,MockActivity 没有启动。可能是什么问题呢?

最佳答案

在您的 View 文件中,您是否将您的 View 绑定(bind)到您的 View 模型?

binding.setViewModel(viewModel);

关于android - 适用于 Android 的 MVVM Activity Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43337026/

相关文章:

android - 自动将 vcard 3.0 导入 android 联系人 (Android 2.1)

安卓工作室 : UnsatisfiedLinkError: findLibrary returned null - loading native library

android - 什么时候应该使用 "spring for android"?

c# - 为什么我的 View 没有在 View 模型更改时更新?

c# - Winforms MVVM GridView 数据绑定(bind)

android - 如何在工具栏上设置 NAVIGATION_MODE_LIST new appcompat v7 21

java - AppUpdateManager.startUpdateFlowForResult 导致 IntentSender$SendIntentException

android - GraphView标签字体大小和间距

MVVM-PRISM,如何在区域/ItemsControl中显示 View 的多个实例

c# - 当 ObservableCollection 从 View 模型公开时,如何对从 ObservableCollection 公开的属性进行数据绑定(bind)?