Coder Social home page Coder Social logo

databindingquickstart's Introduction

DataBindingQuickStart

UltraQuick DataBinding & ViewModel경험하기

MVVM의 기본이 되는 LiveData, ViewModel, DataBinding을 직관적으로 이해하기 위한 소스

app의 build.gradle에서 

plugin에서 다음추가 
apply plugin: 'kotlin-kapt'

...

dependencies에서 다음추가  

kapt "com.android.databinding:compiler:3.0.1"

dataBinding {
    enabled = true
}

DataBinding

  • XML에서는 layout으로 시작하고 그 안에 data와 view를 분리한다.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
>
    <data>
        <variable
                name="BindData"
                type="com.example.databindingquickstart.BindData" />

    </data>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
    >

        <TextView
                android:id="@+id/txt_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:text="@{BindData.showMessage}"
        />

        <TextView
                android:id="@+id/txt_title2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#FF0000"
                android:padding="16dp"
                android:text="@{BindData.showMessage}"
        />

        <TextView
                android:id="@+id/txt_title3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#00BCD4"
                android:padding="16dp"
                android:text="@{BindData.showMessage}"
        />

        <EditText
                android:id="@+id/edt_message"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

    </LinearLayout>

</layout>

빌드가 안될 시

  1. File -> Invalidate Caches / Restart
  2. Build -> Clean Project
  3. Build -> Rebuild Project
  4. Run & Debug시에 빌드가 안되면 File -> Settings에서 Instant Run을 비활성화

databindingquickstart's People

Contributors

vintageappmaker avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.