zoukankan      html  css  js  c++  java
  • viewModels()爆红,修复,添加双向绑定,

    添加依赖

    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    
    implementation "androidx.activity:activity-ktx:1.2.0"
    implementation "androidx.fragment:fragment-ktx:1.3.0"
    
    

    其他依赖,google官方文档下载

    dependencies {
        def lifecycle_version = "2.3.1"
        def arch_version = "2.1.0"
    
        // ViewModel
        implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
        // LiveData
        implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
        // Lifecycles only (without ViewModel or LiveData)
        implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    
        // Saved state module for ViewModel
        implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
    
        // Jetpack Compose Integration for ViewModel
        implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04"
    
        // Annotation processor
        kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
        // alternately - if using Java8, use the following instead of lifecycle-compiler
        implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
    
        // optional - helpers for implementing LifecycleOwner in a Service
        implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
    
        // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
        implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
    
        // optional - ReactiveStreams support for LiveData
        implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
    
        // optional - Test helpers for LiveData
        testImplementation "androidx.arch.core:core-testing:$arch_version"
    }
    

    添加双向绑定

    buildFeatures {
        viewBinding true
    }
    
    这是小睿的博客,如果需要转载,请标注出处啦~ヾ(≧▽≦*)o谢谢。
  • 相关阅读:
    win7下 不支持DOS全屏 This system does not support fullscreen mode
    C语言 猜字游戏
    C语言 寻找字符串的第一个小写字母
    getch 函数 当ubuntu下没有curses.h下怎么办?
    C语言 将小写字母写入文件
    vc++读取文件属性的详细信息描述 读取QQ的注册表路径
    C语言 输入字符写入文件再计算文件里的大写字母个数
    #define STRICT 让编译器进行严格类型检查
    HDU1875 畅通工程再续
    HDU4146 Flip Game
  • 原文地址:https://www.cnblogs.com/Yunrui-blogs/p/14859380.html
Copyright © 2011-2022 走看看