BottomBar icon indicating copy to clipboard operation
BottomBar copied to clipboard

OnTabSelectListener may not work in kotlin 1.1.2-4

Open shiguiyou opened this issue 8 years ago • 0 comments

I copy the demo and convert it into kotlin code,and the OnTabSelectListener doesn't call when i click any tab.

app/build.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

...

compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.roughike:bottom-bar:2.3.1'

bottombar_tabs.xml

<tabs>
  <tab
    id="@+id/tab_favorites"
    icon="@drawable/ic_a"
    title="Favorites" />
  <tab
    id="@+id/tab_nearby"
    icon="@drawable/ic_a"
    title="Nearby" />
  <tab
    id="@+id/tab_friends"
    icon="@drawable/ic_a"
    title="Friends" />
</tabs>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <!-- This could be your fragment container, or something -->
  <FrameLayout
    android:id="@+id/contentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottomBar" />

  <com.roughike.bottombar.BottomBar
    android:id="@+id/bottomBar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    app:bb_tabXmlResource="@xml/bottombar_tabs" />

</RelativeLayout>

MainActivity.kt

import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

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

        bottomBar.setOnTabSelectListener {
            OnTabSelectListener {
                tabId ->
                Log.i("1", "1111111111111111")
                when (tabId) {
                    R.id.tab_favorites -> {
                        supportFragmentManager
                                .beginTransaction()
                                .add(R.id.contentContainer, BlankFragment.newInstance("", ""))
                                .commit()
                    }
                    R.id.tab_nearby -> {
                        supportFragmentManager
                                .beginTransaction()
                                .add(R.id.contentContainer, BlankFragment.newInstance("", ""))
                                .commit()
                    }
                    R.id.tab_friends -> {
                        supportFragmentManager
                                .beginTransaction()
                                .add(R.id.contentContainer, BlankFragment.newInstance("", ""))
                                .commit()
                    }
                }
            }
        }

    }
}

the log(111) doesn't show and the fragment also doesn't show.

the log shows not E level: W/View: requestLayout() improperly called by com.roughike.bottombar.BottomBarTab{814fb17 V.E...CL. ..S...ID 0,6-360,174 #7f0e00ab app:id/tab_favorites} during layout: running second layout pass

shiguiyou avatar Jun 07 '17 02:06 shiguiyou