1
I created a tablayout in my application, I need that by clicking on one of the menu options, it automatically takes the 0 position.
Where the house would be would be an icon to return and the others would be the categories of this particular item. When you click again on the first item that would be the return icon it returns a previous menu.
I tried to remove all tables by selecting one of the tabs and adding new ones, but from the error in the application. It follows how the tablayout structure is:
xml
<com.conformidade.petrobras.apco.helper.CustomTabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabLayout"
android:background="@color/colorPrimary"
app:tabMode="scrollable"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
</com.conformidade.petrobras.apco.helper.CustomTabLayout>
code
//Configura Menu
tabLayout = findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_home_white_24dp));
tabLayout.addTab(tabLayout.newTab().setText("Menu 1"));
tabLayout.addTab(tabLayout.newTab().setText("Menu 2"));
tabLayout.addTab(tabLayout.newTab().setText("Menu 3"));
tabLayout.addTab(tabLayout.newTab().setText("Menu 4"));
tabLayout.setOnTabSelectedListener(new CustomTabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(CustomTabLayout.Tab tab) {
mostrarSubCategorias(tab);
}
@Override
public void onTabUnselected(CustomTabLayout.Tab tab) {
}
@Override
public void onTabReselected(CustomTabLayout.Tab tab) {
}
});
Method to reload tables (Here it error in tabLayout.removeTabAt(j) )
private void mostrarSubCategorias(CustomTabLayout.Tab tab) {
int totalTabs = tabLayout.getTabCount();
int i = tab.getPosition();
for (int j = 0; j < totalTabs; j++) {
if (j != i) {
tabLayout.removeTabAt(j);
}
}
tab.setIcon(R.drawable.ic_keyboard_return_white_24dp).setText("");
}
Does anyone have any idea how else to do that? Because the categories will be dynamic coming from a database where an administrator can delete or add new categories with sub-categories at any time.
Ola @Sanoli, do not change the question to indicate which/how the problem has been solved. If you have found a different response from the community’s proposals, you can answer your own question. I returned the version of your question to the revision 5. Just take a look at our [Tour]. = D
– Icaro Martins