1

I have an app that creates a display of buttons dynamically using this method

public void ButtonLayout() { //Creates new layout and params to go with final LinearLayout llb = (LinearLayout)findViewById(R.id.buttonlayout); //Creates new buttons and indexes for(int i = 0; i < count; i++) { Button displayButton = buttonlist.get(i); //Adds button to view with index and parameters if(displayButton.getTag() == tag || tag == null){ llb.addView(displayButton, i, lp); } } } 

it then opens up a new activity which is a menu, The menu has buttons on it, I want to be able to recall the above method (reload all the buttons) from my menu activity, I cant just start the first activity again.

Is there a way of doing this?

1
  • It's a rude solution, but it's a solution: you can make your activity as a public singleton, so you could get the activity anywhere to do whatever you want. Commented Apr 2, 2013 at 10:48

2 Answers 2

1

I would write class or method where you inject the dependency to a activity and handle your work there

for example:

public class Util{ pulic static void doSomething(LinearLayout llb, List<Buttons> buttonlist){ llb.clear(); // pseudocode for(int i = 0; i < count; i++) { Button displayButton = buttonlist.get(i); //Adds button to view with index and parameters if(displayButton.getTag() == tag || tag == null){ llb.addView(displayButton, i, lp); } } } 
Sign up to request clarification or add additional context in comments.

Comments

0

You can write a Parent activity, which would have this method. The other activities that need to use this method, can extend this parent activity, and can re-use the layout code that you have here.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.