Good day! I have an Expandable navigation drawer and, in fact, a click handler, expressed through switch / case.

@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { String selectedItem = ((List) (mExpandableListData.get(mExpandableListTitle.get(groupPosition)))) .get(childPosition).toString(); getSupportActionBar().setTitle(selectedItem); switch (groupPosition) { case 0: switch (childPosition) { case 0: if (условие) { оператор1; оператор2; } else { оператор1; оператор2; } break; case 1: break; default: break; } break; case 1: switch (childPosition) { case 0: break; case 1: break; default: break; } break; default: break; } mDrawerLayout.closeDrawer(GravityCompat.START); return false; } } ); } 

And everything suits me, but there is a need and now I will explain what. I have a fragment with 2 buttons. This fragment opens in the frame of the main markup (which is loaded into OnCreate) and although there is no code in it so as not to increase it, I call this fragment with 2 buttons in "case 0". By clicking on one button or the second, different text is pulled out, therefore in the markup of the fragment with the buttons there is a TextView where it is pulled out. The problem is that this text is different depending on the "case" menu. Therefore, it is necessary to create another switch in case 0, in case 1, etc. But I do not understand how, so I thought to use if / else as I wrote in the code. Just write in the condition? And although in the application this is the only thing - switching in the menu and these buttons to call for text - will there be any loss of productivity for the user? Yes, it is clumsy, but I'm new, so I plan to do it first so, and then correctly and release it in the update. Thank!

  • one
    If only I understood the problem correctly, I would offer the following: There are some system states (1,2,3 ...). We could create an array that contains a Text string for each state. And instead of case use .Text = Массив[НомерСостояния] - santavital

0