'How to pass data from android Tabs to Tabs with switching?
I'm trying to switch into second tab from first tab when first tab's recycler view item is get clicked. I also want to pass data from first tab to second tab.
When i do pass data using interface, my data is passed successfully but during selecting second tab it shows null. Is there any way to pass data during tab selection?
My code: Interface
public interface InterfaceSendAdapToTab {
public void sendAdapterToTab(String selectedItem);
}
Adapter class:
public class ExpenseAdapter extends RecyclerView.Adapter<ExpenseAdapter.ExpenseSheetHolder> {
TabLayout expenseListTabLayout
String []expenseNames;
InterfaceSendAdapToTab sendAdapToTab;
public ExpenseAdapter(String []expenseNames,InterfaceSendAdapToTab sendAdapToTab,TabLayout expenseListTabLayout){
this.expenseNames=expenseNames;
this.sendAdapToTab=sendAdapToTab;
this.expenseListTabLayout=expenseListTabLayout;
}
@Override
public void onBindViewHolder(@NonNull ExpenseSheetHolder holder, @SuppressLint("RecyclerView") int position) {
holder.cardViews.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendAdapToTab.sendAdapterToTab(expenseNames[position]); //passing data using interface
expenseListTabLayout.getTabAt(1).select(); //switching to second tab
}
});
}
}
androidandroid-fragmentsandroid-recyclerviewfragmentadapterreactjsgoogle-chromegoogle-chrome-extensiondirectory
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

