If you are setting two different views on a button click, why don’t you create two different activities and set content those views in those activities.
Then you can call those activities from those button click listeners. It is fast efficient and your app will not crash.
java.lang.IllegalStateException: Could not find a method ButtonOnClick(View) in the activity class com.example.submenus.MainActivity for onClick handler on view class android.widget.Button with id 'a4button'
This errors means that you do not have a method named ButtonOnClick(View)
for button with id a4button
.
Remove those final modifiers also
solved When i use the back button in activity my app crashes after i click a button in the app