Sometimes I track the flow of user activity in order to get a complete picture of what they are trying to achieve, and often the choice of design that they make is based on the answers they get here, and therefore the nest question is based on the solution posed in the previous question. Sometimes itβs good, in other cases a person does not understand the available design options.
To answer the question:
There are many ways to do this (my list is not exhaustive), I offer several and demonstrate them.
You can use:
- Fragments
- General settings
- intentions
- have resize options in the menu
I decided to demonstrate the fragments, as this is useful for many other things and useful skill.
Create a snippet with your plus and minus buttons, not a separate action. Thus, the fragment has direct access to the methods of the applied activity.
Use your menu options to call the showButtonOptions () method of your activity.
As part of your business:
Fragment fragment; FrameLayout frameLayout; @Override protected void onCreate(Bundle savedInstanceState) { ..../ View view = this.findViewById(android.R.id.My_Activity); frameLayout = (FrameLayout) findViewById(R.id.fragFrame); ..../ } public void ChangeMyLayoutMethod(args){ ..../ //use args to make change. } public void showButtonOptions() { // Create new fragment and transaction fragment = new MyPlusAndMinusButtonFragment(); fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.fragFrame, fragment); fragmentTransaction.commit(); frameLayout.setVisibility(View.VISIBLE); } public void returnToActivity() { frameLayout.setVisibility(View.GONE); // To do manage your back stack. }
In your activity xml
<RelativeLayout ... or whatever ...> .../ Details of that activity <FrameLayout android:id="@+id/fragFrame" android:layout_below="@+id/wherever" android:layout_height="your choice" android:layout_width="your choice" android:layout_marginTop=".. etc" android:visibility="gone"> </RelativeLayout>
Create snippet:
public class MyPlusAndMinusButtonFragment extends Fragment { FragmentManager fragmentManager; ..../ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.My_Plus_And_Minus_Button_Fragment, container, false); fragmentManager = getFragmentManager(); ...../ return view; } //To Do // Manage button clicks// onClick(){ // Call the parent activity // Cast this activity to type of parent activity. ((MyActivity) getActivity()).ChangeMyLayoutMethod(args); }
Fragment Layout, My_Plus_And_Minus_Button_Fragment.xml:
<FrameLayout .....> <RelativeLayout ....> <ImageButtons etc... ..../ </RelativeLayout> </FrameLayout>
As with most software development decisions, there can be many correct decisions, some of them are better than others, some of them are just a matter of preferred design choice. As long as we have no options, we have no choice.