在mvvm模式中在布局内使用枚举

时间:2018-07-12 07:03:53

标签: android android-layout mvvm

我怎么使用

class public enum AttacheType {
                VIDEOCAMERA, VIDEOGALARY, PHOTOCAMERA, PHOTOGALARY
 } 

在代码的指示部分?

      <import type="CreatePostViewModel.AttacheType" />
     </data>

     <ImageView
        android:id="@+id/Add_Video_ImageViewk"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="0.1"
         android:onClick="@{ () -> viewModel.addAttachment("HERE PLEASE")}"/>

2 个答案:

答案 0 :(得分:1)

<layout>
    <data>
        <variable
            name="attachType"
            type="com.packagename.CreatePostViewModel.AttacheType"/>
    </data>
    <ImageView
        android:id="@+id/Add_Video_ImageViewk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:onClick="@{ () -> viewModel.addAttachment(attachType.VIDEOGALARY)}"/>
</layout>

使用完整的包名和类添加您的枚举

答案 1 :(得分:0)

尝试一下:-

将枚举放入您的#include<iostream> using namespace std; class swap_values { int a, b, temp; public: swap_values(){ a=0;b=0;temp=0; } swap_values(int x, int y){ a = x; b = y; temp = 0; } void swapped() { temp = b; b=a; a=temp; } void print(){ cout<<"a: "<<a<<" b: "<<b<<endl; } }; int main() { int x =10; int y = 20; swap_values obj(x, y); obj.print(); obj.swapped(); obj.print(); return 0; } 文件中:-

Resource

将其用作:-

<attr name="AttacheType" format="enum">
         <enum name="None" value="VIDEOCAMERA"/>
         <enum name="One" value="VIDEOGALARY"/>
         <enum name="Two" value="PHOTOCAMERA"/>
         <enum name="Three" value="PHOTOGALARY"/>
</attr>