My problem is that I need to access my LayoutNameBinding, but I am unable to do so. Only DataBinding generated class which is available is LayoutNameBindingImpl.
- Build is successful (No errors)
- DataBinding is enabled within build.gradle(:app)
- DataBinding plugin kotlin-apt is applied within build.gradle(:app)
- My layout is contained within a
<layout>
- LobbyFragmentBinding.java is generated and contains LobbyFragmentBinding
The commented part is what I would like to be able to do within my code. Part of the code shown is inspired of https://github.com/android/sunflower which explains how to use different parts of Android JetPack.
Solutions tried
- Rebuild
- Manually add "import com.kotlin.projet3.databinding.LobbyFragmentBinding"
- Solutions found at android: data binding error: cannot find symbol class (Problem is not the same, but tried anyways)
- Solutions found at Data Binding class not generated (Problem is not the same, but tried anyways)
LobbyFragment.kt
package com.kotlin.projet3.ui.lobby
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import com.kotlin.projet3.R
import com.kotlin.projet3.adapters.GAME_LIST_INDEX
import com.kotlin.projet3.adapters.MATCH_HISTORY_INDEX
import com.kotlin.projet3.adapters.PROFILE_INDEX
import com.kotlin.projet3.databinding.LobbyFragmentBindingImpl
class LobbyFragment : Fragment(){
private lateinit var nav: NavController
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// val binding = LobbyFragmentBinding.inflate(inflater,container,false)
//
// viewPager = binding.viewPager
// viewPager.adapter = LobbyTabsAdapter(this)
//
// TabLayoutMediator(binding.tabs, viewPager) { tab, position ->
// tab.setIcon(getTabIcon(position))
// tab.text = getTabTitle(position)
// }.attach()
//
// return binding.root
return super.onCreateView(inflater, container, savedInstanceState)
}
private fun getTabIcon(position: Int): Int {
return when (position) {
GAME_LIST_INDEX -> R.drawable.ic_home_black_24dp
PROFILE_INDEX -> R.drawable.ic_person_black_24dp
MATCH_HISTORY_INDEX -> R.drawable.ic_assessment_black_24dp
else -> throw IndexOutOfBoundsException()
}
}
private fun getTabTitle(position: Int): String? {
return when (position) {
GAME_LIST_INDEX -> getString(R.string.home_button)
PROFILE_INDEX -> getString(R.string.profile_button)
MATCH_HISTORY_INDEX -> getString(R.string.match_history_button)
else -> null
}
}
}
lobby_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/page_container"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="parent">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/view_pager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent=".15"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorFullWidth="true" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/tabs"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
LobbyFragmentBinding.java (Generated file)
// Generated by data binding compiler. Do not edit!
package com.kotlin.projet3.databinding;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.kotlin.projet3.R;
import java.lang.Deprecated;
import java.lang.Object;
public abstract class LobbyFragmentBinding extends ViewDataBinding {
@NonNull
public final ConstraintLayout pageContainer;
@NonNull
public final TabLayout tabs;
@NonNull
public final ViewPager2 viewPager;
protected LobbyFragmentBinding(Object _bindingComponent, View _root, int _localFieldCount,
ConstraintLayout pageContainer, TabLayout tabs, ViewPager2 viewPager) {
super(_bindingComponent, _root, _localFieldCount);
this.pageContainer = pageContainer;
this.tabs = tabs;
this.viewPager = viewPager;
}
@NonNull
public static LobbyFragmentBinding inflate(@NonNull LayoutInflater inflater,
@Nullable ViewGroup root, boolean attachToRoot) {
return inflate(inflater, root, attachToRoot, DataBindingUtil.getDefaultComponent());
}
/**
* This method receives DataBindingComponent instance as type Object instead of
* type DataBindingComponent to avoid causing too many compilation errors if
* compilation fails for another reason.
* https://issuetracker.google.com/issues/116541301
* @Deprecated Use DataBindingUtil.inflate(inflater, R.layout.lobby_fragment, root, attachToRoot, component)
*/
@NonNull
@Deprecated
public static LobbyFragmentBinding inflate(@NonNull LayoutInflater inflater,
@Nullable ViewGroup root, boolean attachToRoot, @Nullable Object component) {
return ViewDataBinding.<LobbyFragmentBinding>inflateInternal(inflater, R.layout.lobby_fragment, root, attachToRoot, component);
}
@NonNull
public static LobbyFragmentBinding inflate(@NonNull LayoutInflater inflater) {
return inflate(inflater, DataBindingUtil.getDefaultComponent());
}
/**
* This method receives DataBindingComponent instance as type Object instead of
* type DataBindingComponent to avoid causing too many compilation errors if
* compilation fails for another reason.
* https://issuetracker.google.com/issues/116541301
* @Deprecated Use DataBindingUtil.inflate(inflater, R.layout.lobby_fragment, null, false, component)
*/
@NonNull
@Deprecated
public static LobbyFragmentBinding inflate(@NonNull LayoutInflater inflater,
@Nullable Object component) {
return ViewDataBinding.<LobbyFragmentBinding>inflateInternal(inflater, R.layout.lobby_fragment, null, false, component);
}
public static LobbyFragmentBinding bind(@NonNull View view) {
return bind(view, DataBindingUtil.getDefaultComponent());
}
/**
* This method receives DataBindingComponent instance as type Object instead of
* type DataBindingComponent to avoid causing too many compilation errors if
* compilation fails for another reason.
* https://issuetracker.google.com/issues/116541301
* @Deprecated Use DataBindingUtil.bind(view, component)
*/
@Deprecated
public static LobbyFragmentBinding bind(@NonNull View view, @Nullable Object component) {
return (LobbyFragmentBinding)bind(component, view, R.layout.lobby_fragment);
}
}