michael-rapp / ChromeLikeTabSwitcher

Provides a tab switcher similar to the one, which is used in Google Chrome on Android
Apache License 2.0
1.23k stars 140 forks source link

chrome like tab switcher #28

Closed ayushnitra closed 4 years ago

ayushnitra commented 4 years ago

Sir How can we work click event or any other event on the tab layout 1 or tab layout 2 Please reply.

michael-rapp commented 4 years ago

I am not sure if I understand your question correctly. I guess you want to assign event handlers to views that are contained by individual tabs.

In your code you should have a class that extends TabSwitcherDecorator or StatefulTabSwitcherDecorator and overrides the method onShowTab. This is the proper place to initialize the views that are contained in a tab, e.g.:

@Override
public void onShowTab(@NonNull final Context context,
                                      @NonNull final TabSwitcher tabSwitcher, @NonNull final View view,
                                      @NonNull final Tab tab, final int index, final int viewType,
                                      @Nullable final State state,
                                      @Nullable final Bundle savedInstanceState) {
    Button button = findViewById(R.id.button);
    button.setOnClickListener(...)
}

Please refer to the example app, where a similar piece of code can be found in the class Decorator in MainActivity.