android-viewbinding

Why using View Binding is changing the layout?

情到浓时终转凉″ 提交于 2020-07-09 14:32:40
问题 Actual Code: My Main Activity: class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) val rollButton = binding.rollButton rollButton.setOnClickListener { rollDice() } setContentView(binding.root) } private fun rollDice() { val randomDiceRoll = Random.nextInt(6) + 1 Toast.makeText(this, randomDiceRoll.toString(),

Android ViewBinding with CustomView

Deadly 提交于 2020-06-27 16:01:27
问题 I'd like to use try out the ViewBinding with custom view, for example: MainActivity <=> layout_main.xml MyCustomView <=> layout_my_custom_view.xml layout_main.xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.myapplication.MyCustomView android:id="@+id/custom_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> layout_my_custom_view.xml

Android ViewBinding with CustomView

冷暖自知 提交于 2020-06-27 16:01:19
问题 I'd like to use try out the ViewBinding with custom view, for example: MainActivity <=> layout_main.xml MyCustomView <=> layout_my_custom_view.xml layout_main.xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.myapplication.MyCustomView android:id="@+id/custom_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> layout_my_custom_view.xml

How can I replace ButterKnife with ViewBinding on RecyclerView Adapter

吃可爱长大的小学妹 提交于 2020-05-14 12:12:06
问题 I would like to use the new View Binding instead of ButterKnife in my RecyclerView Adapter class ? This is my class : import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.cardview.widget.CardView; import androidx.recyclerview.widget.RecyclerView; import com.gallosalocin.mareu.R; import com.gallosalocin.mareu.model.Meeting; import java

How can I replace ButterKnife with ViewBinding on RecyclerView Adapter

北城余情 提交于 2020-05-14 12:12:01
问题 I would like to use the new View Binding instead of ButterKnife in my RecyclerView Adapter class ? This is my class : import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.cardview.widget.CardView; import androidx.recyclerview.widget.RecyclerView; import com.gallosalocin.mareu.R; import com.gallosalocin.mareu.model.Meeting; import java

ViewBinding vs Kotlin Android Extensions with synthetic views

自古美人都是妖i 提交于 2020-04-29 06:08:22
问题 How does the new ViewBinding compare with the Kotlin Android Extensions with synthetic views bindings? Apart form the NullSafety and TypeSafety provided by new ViewBindings, why should we consider ditching the Kotlin way of using synthetic bindings on Views. Is the new ViewBinding more performat since it generates the Binding class before hand? 回答1: Let's review the two. Configuration Kotlin Android Extensions Import appropriate layout synthetic extensions: import kotlinx.android.synthetic

ViewBinding vs Kotlin Android Extensions with synthetic views

人走茶凉 提交于 2020-04-29 06:08:17
问题 How does the new ViewBinding compare with the Kotlin Android Extensions with synthetic views bindings? Apart form the NullSafety and TypeSafety provided by new ViewBindings, why should we consider ditching the Kotlin way of using synthetic bindings on Views. Is the new ViewBinding more performat since it generates the Binding class before hand? 回答1: Let's review the two. Configuration Kotlin Android Extensions Import appropriate layout synthetic extensions: import kotlinx.android.synthetic

ViewBinding - how to get binding for included layouts?

◇◆丶佛笑我妖孽 提交于 2020-04-26 18:34:38
问题 While working with ViewBinding I come across few not documented cases. First: How to get binding for included generic view layout parts, main binding see only items in main layout? Second: How to get binding for included merge type layout parts, again main binding see only items in main layout? 回答1: In case of: Include with generic layout (not merge node), we need to assign ID to included part, this way in binding we will have access to included sub part <include android:id="@+id/your_id"

ViewBinding - how to get binding for included layouts?

雨燕双飞 提交于 2020-04-26 18:26:33
问题 While working with ViewBinding I come across few not documented cases. First: How to get binding for included generic view layout parts, main binding see only items in main layout? Second: How to get binding for included merge type layout parts, again main binding see only items in main layout? 回答1: In case of: Include with generic layout (not merge node), we need to assign ID to included part, this way in binding we will have access to included sub part <include android:id="@+id/your_id"