带有微调器的 Android 数据绑定

问题描述

我正在尝试从我的 viewmodel 更新微调器的值,但我还没有。

在 main_activity_app_bar.xml 中,我有以下代码

playerView.setonTouchListener(new OnSwipetouchListener(this){
        public void onSwipetop() {
            Toast.makeText(VideoPlayerActivity.this,"top",Toast.LENGTH_SHORT).show();
        }
        public void onSwipeRight() {
            Toast.makeText(VideoPlayerActivity.this,"right",Toast.LENGTH_SHORT).show();
        }
        public void onSwipeLeft() {
            Toast.makeText(VideoPlayerActivity.this,"left",Toast.LENGTH_SHORT).show();
        }
        public void onSwipeBottom() {
            Toast.makeText(VideoPlayerActivity.this,"bottom",Toast.LENGTH_SHORT).show();
        }
    });

在 MainActivity 我有

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <variable
            name="viewmodel"
            type="com.developments.accountify_v3.views.MainActivityviewmodel" />
    </data>
    ....

    <Spinner
                    android:visibility="visible"
                    android:id="@+id/spinnerYears"
                    android:layout_alignParentEnd="true"
                    android:layout_width="wrap_content"
                    android:paddingLeft="20dp"
                    android:paddingRight="20dp"
                    android:textAlignment="center"
                    android:layout_height="match_parent"
                    android:overlapAnchor="false"
                    android:entries="@{viewmodel.listofYears}"/>

    ...

</layout>

在 MainActivityviewmodel 中:

containerBinding = MainActivityContainerBinding.inflate(getLayoutInflater());
setContentView(containerBinding.getRoot());

mainActivityviewmodel = new viewmodelProvider(this).get(MainActivityviewmodel.class);
mainActivityviewmodel.getlistofYears();

问题是微调器没有使用列表中的值进行更新。任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)