0

I'm using TableLayout. On the click of a Button, I am supposed to hide it and show a progress bar and once the progress bar is done (e.g. downloading a file), I need to hide that and show a different button. The UI gets messed up, if I define these UI elements in the XML layout file. The Progess bar and new button shows as a new column. Any clue how I could dynamically hide and replace a button with progress bar and later a new button?

Zong
  • 6,160
  • 5
  • 32
  • 46
user3277846
  • 1,019
  • 1
  • 10
  • 15

2 Answers2

1

When you create your button use yourButton.setTag(Object) to tag them, later you can find your desired button with findViewByTag(Object) function.

Take a look at this: What is the main purpose of setTag() getTag() methods of View?

For example you can tag every of your buttons with string positionX + "," + positionY

Community
  • 1
  • 1
Than
  • 2,759
  • 1
  • 20
  • 41
0

Android allows the use of a setVisibility method call on Views.

  • Set up the xml where you want it, you are actually able to put things on top of each other but i wouldn't recommmend it.

  • In your onCreate() method ensure that the fields/Buttons/Views are allcreated but then set the visibility to setVisibility(View.INVISIBLE); followed by setEnabled(false);

  • Once you have figured out your UI flow (the actual progression through the process), determine where each view/button/field are to be displayed or hidden and code in where this needs to happen.

  • To ensure that the flow works, and reduce the chance of a user entering a state in-which your views are loading in at the wrong time, create boolean variables and maybe getters and setters to create logic rules that are applicable.

  • setVisibility(View.VISIBLE), setVisibility(View.INVISIBLE) are what you are looking for.

Mike Docherty
  • 167
  • 2
  • 13