Hy alle! :)Tabitem Bindung in android Studio
Ich brauche ein benutzerdefiniertes Layout in der Registerkarte Aktivität (oder Fragment) tabtitem.
First-> definierte ich dieses Layout für den TabItem: tab_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="@+id/tab_item_root_linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tab_item_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Wink from"/>
<TextView
android:id="@+id/tab_item_number_text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="1"/>
</LinearLayout>
</layout>
Layout-Tags für die Databinding benötigt.
Second-> definiert eine tablayout (im Fragment, aber ich habe das nicht angeschlossen): fragment_surf_base.xml (dies ist das Fragment mit tablayout)
<android.support.design.widget.TabLayout
android:id="@+id/surf_tab_layout"
android:layout_width="368dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TabItem
android:id="@+id/tabItem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_item_layout" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_item_layout" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_item_layout" />
</android.support.design.widget.TabLayout>
Und ich brauche für die Registerkarte Artikel (mit Bindung) in der Java-Datei mit diesen Codes:
Initilazie meiner Bindung Klasseninstanz:
binding = DataBindingUtil.inflate(inflater,R.layout.fragment_surf_base, container, false);
Nun, diese bindende Instanz in Verwendung (null zurückgeben !! aber warum ?):
binding.tabItem1; Das ist null, aber ich weiß nicht warum?
Und ich brauche die TabItem Layout-Elemente (tab_item_name_text_view und tab_item_number_text_view) mit der tab_item_layout Bindungsklasseninstanz durch die binding.tabItem1.bindingClassInstanceReturnedItem < < - Aber ich habe nicht: \
Jede Idee für dieses Problem? : \ Tschüss! :)
(Leider mein schlechtes Englisch)
Ich weiß das. Aber ich brauche die Tabitem-Layout-Elemente binden. Beispiel: binding.tabitem1.nameTextView.setText ("asdad"). Edit: Und die binding.tabItem1 ist null aber ich benutze die tablayout.getTabAt (0) das ist nicht null, aber das ist eine tablayout.tab und das ich nicht Casting zu tabitem oder andere. –