Android DataBinding - 시작
DataBinding
-
gradle 수정
app수준의 gradle에 다음과 같이 추가합니다.
android{ ... dataBinding{ enabled =true } }
- Activity
- Java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityMainBinding binding = DataBindingUtil.setContentView(this,R.layout.activity_main); }
- Kotlin
override fun onCreate(savedInstanceState: Bundle?) { val binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main) }
- Java
- Fragment
- Java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FragmentBlankBinding binding = DataBindingUtil.inflate(inflater,R.layout.fragment_blank,container,false); return binding.getRoot(); }
- Kotlin
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val binding = DataBindingUtil.inflate<ViewDataBinding>(inflater, R.layout.fragment_search, container, false) }
- Java
-
참조
Leave a comment