-1

I`m new here and need help. This my code.

Activity

class ProfileActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_profile)
    var adapter: PagerAdapter = IntroSliderAdapter(applicationContext)
    viewpager.adapter = adapter
}

Adapter

class IntroSliderAdapter(var context: Context) : PagerAdapter() {

lateinit var inflater: LayoutInflater
var texts: Array<Int> = arrayOf(R.string.intro_text1,R.string.intro_text2,R.string.intro_text3)

override fun isViewFromObject(view: View, `object`: Any): Boolean = view == `object` as ConstraintLayout

override fun getCount(): Int = texts.size

override fun instantiateItem(container: ViewGroup, position: Int): Any {
    inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
    var view: View = inflater.inflate(R.layout.intro_slider, container, false)
    Log.i("INFO", "View: " + view.toString())
    Log.i("INFO", "Container:" + container.toString())

    container!!.addView(view)
    return view
}

override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
    container!!.removeView(`object` as ConstraintLayout)
}

activity layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/profileContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    tools:context=".ProfileActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v4.view.ViewPager>

</RelativeLayout>

slider layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:id="@+id/introLayout">

    <ImageView
        android:id="@+id/mainLogo"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:layout_marginEnd="8dp"
        android:contentDescription="@string/app_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/logo" />

    <TextView
        android:id="@+id/introText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test text"
    ...

</android.support.constraint.ConstraintLayout>

How I understood inflater.inflate(R.layout.intro_slider, container, false) must push intro_slider.xml content to view, but when I run my application I see just empty slides. Plz, help me understand why it's happening.

  • Do you have any error at Logs ? Please try with Logs and try to show a normal Log step by step because I think the problem is somewhere with xml – TheCoderGuy Jan 06 '19 at 00:24
  • 1
    Yes, you`re right! I found a few warnings and some not correct parameters in my xml(for example, I fixed app:srcCompat to android:src). Thanks – Andrii Lytovchenko Jan 06 '19 at 15:53

1 Answers1

1

In my case problem was in complex of mistakes. But main problem was: not correct filled xml layout, for example, my logo image not been visible because app:srcCompat must be android:src and so on..

Thanks Spritzig for help!