본문 바로가기

android

[j android] Databinding 세팅하기

728x90
반응형

1. 안드로이드 개발의 시작! Gradle Setting

1. gradle app수준

apply plugin: 'com.android.application'

android {
....
	dataBinding {
		enabled = true
	}
}

 

 

 

2. xml 세팅

<layout></layout>으로 감싸준다.

 

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
...

</layout>

 

3. activity 세팅

- 코틀린

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var binding: ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        
    }
}

-자바

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
    }
}
728x90
반응형