Androidda databinding

+6 ovoz
51 marta ko‘rilgan
so‘radi 05 fevral, 17 Axrorxo'ja (733 bal)

Assalom alaykum,

Android da view o'zgaruvchilarni inject qilish uchun ButterKnife ishlataman, lekin yaqinda android ni o'zida databind flagni yoqib qo'ysa code quyidagicha bo'larkan 

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="user"
            type="com.example.myapp.model.User"/>
    </data>
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <ImageView
                android:src="@{user.image}"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        <TextView
                android:text="@{user.firstName}"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <TextView
                android:text="@{user.lastName}"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
    </LinearLayout>
</layout>

va bind qilish quyidagicha 

UserInfoBinding binding =UserInfoBinding.inflate(getLayoutInflater(), root, true);
binding.setUser(user);

ButterKnife dan ko'ra anchagina qisqa code.

1 ta javob

0 ovoz
javob berdi 06 yanvar Kenjebaev (883 bal)
 
Eng yaxshi javob
Тавсия учун раҳмат :)

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...