Kriti Jain Kriti Jain - 2 months ago 42
Android Question

How to Start Activity from Bottom Navigation Drawer?

I am developing an application which contains bottom navigation drawer, Till now every thing is working fine but when i am adding click listener, the action which i am performing is not working.

bottombar_tabs.xml

<?xml version="1.0" encoding="utf-8"?>
<tabs xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent">

<tab
android:layout_height="50dp"
android:id="@+id/tab_favorites"
android:icon="@mipmap/ic_map_black_24dp"
android:title="Land" />

<tab
android:layout_height="50dp"
android:id="@+id/tab_nearby"
android:icon="@mipmap/ic_directions"
android:title="Vehicle" />

<tab
android:layout_height="50dp"
android:id="@+id/tab_friends"
android:icon="@mipmap/ic_inbox_black_24dp"
android:title="Equipment" />

</tabs>


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">


<android.support.v7.widget.RecyclerView
android:id="@+id/fishPriceList"
android:layout_marginBottom="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:layout_weight="1"/>

<android.support.design.widget.FloatingActionButton

android:id="@+id/fab"
android:background="#003300"
app:backgroundTint="@color/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="70dp"
android:layout_gravity="bottom|end"
android:layout_marginRight="@dimen/fab_margin"
android:src="@mipmap/ic_filter_list" />


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


</RelativeLayout>


In java class

public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabReselectListener(new OnTabReselectListener() {
@Override
public void onTabReSelected(@IdRes int tabId) {

if (tabId == R.id.tab_nearby){
Toast.makeText(getApplicationContext(),"Working",Toast.LENGTH_LONG).show();
}

}
});
}
}

Answer

Try like this

 bottomBar.setOnTabselectListener(new OnTabselectListener() {
        @Override
        public void onTabSelected(@IdRes int tabId) {
            Toast.makeText(this, "Hello How are you?", Toast.LENGTH_LONG).show();
        }
    });
Comments