0

I am developing a game in Android. The game is implemented in the MainActivity.java and uses Relative Layout in xml. I want to implement a pause button, which when clicked opens a pop-up window with buttons for options like "1 player","2 Player","Change skin",'Challenge Friend" etc.

1.How to create a layout at runtime with the buttons and can we destroy the layout when an option is clicked.

2.Can we get the id of the option button clicked in the dynamically created layout, to the MainActivity, so that the corresponding function can be called.

3.when dynamically creating the layout, will the values of the already existing layout be reset?

4.Is dynamically creating layout and destroying it very expensive?

I am new to android and so would really appreciate some help...Thankyou!!!

Aparna
  • 835
  • 2
  • 23
  • 47
  • Why not statically create a layout in xml, using the specification you describe and change its visibility dynamically. That's cheaper. – John Feb 27 '15 at 15:19
  • I have a relative layout in the main xml.Can I just create another layout and make it's visibility "gone" or something? Can we have 2 layouts in one xml?.So will each layout need to have an id so that I can make it visible when I want? – Aparna Feb 27 '15 at 16:06
  • Yes, that's right, use `FrameLayout` as the root Layout and under that the rest can by found by id and made "gone", or pop up a new activity to swallow touches – John Feb 27 '15 at 16:14

2 Answers2

1

Sounds like you just need an alert dialog with three buttons? Use the onlick functions in this answer. If you need an image view in the pop up see this answer and use similar tactics.

Community
  • 1
  • 1
MarcusM.
  • 86
  • 6
  • In addition you can style the pop up in styles.xml to give the effect you want in a very inexpensive way. [This answer](http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog) – MarcusM. Feb 27 '15 at 15:22
0

If you want a custom dialog with custom layout , use DialogFragment : http://developer.android.com/reference/android/app/DialogFragment.html

Bubu
  • 1,533
  • 14
  • 14