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?

KingM0ses
  • 44
  • 7
  • 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. – Drewen Apr 02 '13 at 10:48

2 Answers2

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);
        }
    }
}
MemLeak
  • 4,456
  • 4
  • 45
  • 84
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.

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68