2017. 8. 8. 13:35ㆍMobile/Android
build.gradle 추가
dataBinding {
enabled = true
}
XML
<layout xmlns:android="http://schemas.android.com/apk/res/android" >
<!--기존 layout 틀 -->
</layout>
Java
JoinMberBinding bd;
//setContentView(R.layout.join_mber);
bd = DataBindingUtil.setContentView(this,R.layout.join_mber);
bd.setAt(this);
JoinMberBinding 은 Rebuild project or Sync project 해주시면 됩니다.
bd.textview.setText("하이");
버터나이프 비슷한 점이 많다 일단 findViewById 노가다를 안해서 좋군
클릭 이벤트 !
XML
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<data>
<variable
name="at"
type="innov.contact.login.JoinMberActivity"/>
</data>
<!--기존 layout 틀 -->
<Button
android:onClick="@{at::onClickValid}
android:onClick="@{(view) -> at.onClickValid(view)}"
>
</layout>
JAVA
public void onClickValid(View view){
Logger.d("클릭");
}
이런식으로 쓸수도 있다
android:text="@{String.valueOf(index + 1)}" android:visibility="@{age < 13 ? View.GONE : View.VISIBLE}" android:transitionName='@{"image_" + id}'
참고-
https://developer.android.com/topic/libraries/data-binding/index.html?hl=ko
'Mobile > Android' 카테고리의 다른 글
Android Error java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() (0) | 2017.09.25 |
---|---|
Android stetho (크롬 디버깅) (0) | 2017.08.27 |
Android JSON using GSON 쉽게 변환 (0) | 2017.07.14 |
Android Studio Class Diagram 만들기 (1) | 2017.06.24 |
갤럭시탭S3 개봉기 + 정품등록 (0) | 2017.06.22 |