Привет, я учусь делать приложение для Android, и пытаюсь добавить видовой пейджер ... Я читал здесь урок: https://developer.android.com/training/animation/screen-slide-2
Однако я, кажется, получаюошибка: Class 'ScreenSlidePagerAdapter' is not abstract and does not implement abstract base class member @NonNull public abstract fun createFragment(p0: Int): Fragment defined in androidx.viewpager2.adapter.FragmentStateAdapter
Мой код в значительной степени идентичен учебным классам ScreenSlidePagerActivity, поэтому я не уверен, в чем проблема!
package com.main.treasurex.ui.home
import android.os.Bundle
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.main.treasurex.R
import androidx.viewpager2.adapter.FragmentStateAdapter
/**
* The number of pages (wizard steps) to show in this demo.
*/
private const val NUM_PAGES = 5
class SlideFragmentActive : FragmentActivity() {
/**
* The pager widget, which handles animation and allows swiping horizontally to access previous
* and next wizard steps.
*/
private lateinit var mPager: ViewPager2
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.fragment_sample)
// Instantiate a ViewPager and a PagerAdapter.
mPager = findViewById(R.id.pager)
// The pager adapter, which provides the pages to the view pager widget.
val pagerAdapter = ScreenSlidePagerAdapter(this)
mPager.adapter = pagerAdapter
}
override fun onBackPressed() {
if (mPager.currentItem == 0) {
// If the user is currently looking at the first step, allow the system to handle the
// Back button. This calls finish() on this activity and pops the back stack.
super.onBackPressed()
} else {
// Otherwise, select the previous step.
mPager.currentItem = mPager.currentItem - 1
}
}
/**
* A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in
* sequence.
*/
private inner class ScreenSlidePagerAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {
override fun getItemCount(): Int = NUM_PAGES
override fun getItem(position: Int): Fragment = SlideFragment()
}
}
Зависимости
dependencies {
//noinspection GradleCompatible
implementation "androidx.viewpager2:viewpager2:1.0.0-beta04"
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.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
Спасибо за всю помощь в продвинутом !!!!!!!ED