last day (15 days later) » 

10:42
0
A: ViewPager2 fragments overlap tabbed items

Nilesh RathodThere is no issue with ViewPager2 The issue is with your layout file check the result when i change your CoordinatorLayout with LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/r...

Thanks, how can I add layout to the tab instead of just using tab.text = "Tab $position"
@HasanAYousef didn't get you can you explore more
I want to display fragment in the tab, not just text element
@HasanAYousef you want to display fragment name instead of tab.text = "Tab $position"
I got this error: ` java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lan‌​g/String;Ljava/lang/‌​invoke/MethodType;Lj‌​ava/lang/invoke/Meth‌​odType;Ljava/lang/in‌​voke/MethodHandle;Lj‌​ava/lang/invoke/Meth‌​odType;)Ljava/lang/i‌​nvoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar) at com.google.android.material.tabs.TabLayout$TabView.addOnLayo‌​utChangeListener(Tab‌​Layout.java:2592)`
10:42
@HasanAYousef i'm asking again what you want to achieve
10:55
@HasanAYousef hello
Thanks for your answers
I'll summarize what I'm trying to do
simple viewpager2 with 2 taps
each tap will load a diffrent layout
I thought to use fragments
but looks viewpager2 not yet finalized, so I'm getting some issues
the one I shared before
and now, with upgrading to beta
I'm getting the error
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
    at com.google.android.material.tabs.TabLayout$TabView.addOnLayoutChangeListener(TabLayout.java:2592)
@HasanAYousef use this dependencies `implementation 'com.google.android.material:material:1.1.0-alpha08'
implementation 'androidx.viewpager2:viewpager2:1.0.0-beta02'`
already updated it
share your current code
class MainActivity : AppCompatActivity(), SettingsFragment.OnFragmentInteractionListener {
override fun onFragmentInteraction(uri: Uri) {

}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

viewpager.adapter = AppViewPagerAdapter(supportFragmentManager, lifecycle)

TabLayoutMediator(tabs, viewpager,
TabLayoutMediator.OnConfigureTabCallback { tab, position ->
// Styling each tab here
tab.text = "Tab $position"
}).attach()
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'

implementation 'com.google.android.material:material:1.1.0-alpha08'
implementation 'androidx.viewpager2:viewpager2:1.0.0-beta02'

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
class AppViewPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
FragmentStateAdapter(fragmentManager, lifecycle) {
override fun getItemCount(): Int {
return 3
}

override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> SettingsFragment.newInstance()
1 -> SettingsFragment.newInstance()
else -> SettingsFragment.newInstance()
}
}
}
class SettingsFragment : Fragment() {
private var listener: OnFragmentInteractionListener? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_settings, container, false)
}

// TODO: Rename method, update argument and hook method into UI event
fun onButtonPressed(uri: Uri) {
11:14
@HasanAYousef can u share your code as github ripo so i can reproduce same error
ok, few minutes to get it there
11:32
@HasanAYousef for me you code is working fine
activity code

package com.nilu.demoapplication

import android.annotation.SuppressLint
import android.graphics.Color
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.content.ContextCompat
import kotlinx.android.synthetic.main.activity_main.*
import com.google.android.material.tabs.TabLayoutMediator

import com.google.android.material.tabs.TabLayout
import com.google.android.material.badge.BadgeUtils
import com.google.android.material.badge.BadgeDrawable
adapter code

package com.nilu.demoapplication

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter


class AppViewPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
FragmentStateAdapter(fragmentManager, lifecycle) {
override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> SettingsFragment.newInstance()
1 -> SettingsFragment.newInstance()
Fragment code
*********************
The error disappear if I removed his:
    TabLayoutMediator(tabs, viewpager,
        TabLayoutMediator.OnConfigureTabCallback { tab, position ->
            // Styling each tab here
            tab.text = "Tab $position"
        }).attach()
******************
layout code
Gradle file

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.nilu.demoapplication"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
package com.nilu.demoapplication


import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup



/**
* A simple [Fragment] subclass.
*
*/
import android.content.Context
import android.net.Uri


class SettingsFragment : Fragment() {
private var listener: OnFragmentInteractionListener? = null

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
@HasanAYousef check out above codes
@HasanAYousef make sure you have added ` compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
` iin your build.gradle file
let m check it
The taps are ok now, but the content of the fragments is not appearing! it is empty
It appeared once I removed the <com.google.android.material.appbar.AppBarLayout> from the mainactivity layout
Just use simple linear layout
if you are using toolbar then add this in your activity setSupportActionBar(toolbar)
11:58
Thanks a lot, it is ok now
@HasanAYousef Glad to have been of help! Feel free to accept my answer if you feel it was useful to you. :-)

last day (15 days later) »