0

I'm trying to write an Android application where I need to change significant elements of my layout at runtime. I could implement it by programatically moving Views around the screen, but that would take a lot of time and a lot of work. A simpler method would be to flush the current layout and reload the screen layout from a new layout file. However, it appears that all the API methods that made this method practical are from API 11, while I'm developing for API 10 (specifically OS 2.3.4).

To be more specific, I'm developing a calculator. I would like to implement a change-of-base feature to change between, for example, Decimal, Hex, and Binary. Since, for example, Binary does not need the digits 2-9, I would like to restructure the layout both for L&F purposes as well as to recover screen real-estate rather than simply greying out the unused buttons.

I found this tutorial in the responses to a similar question, but the information there appears to be horribly outdated, and what information I can glean from that does not appear to work in my circumstance.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Ertai87
  • 1,156
  • 1
  • 15
  • 26
  • http://developer.android.com/training/basics/fragments/support-lib.html – zapl Aug 24 '12 at 15:30
  • WOW THAT SUPPORT LIBRARY THING LOOKS SWEET! That looks like it'll solve the problem; I'm pretty sure I can do it easily with Fragments, but I didn't think I could use Fragments pre-API 11. I'll try that out and get back to you. – Ertai87 Aug 30 '12 at 03:55
  • Tried it. Couldn't get fragments to work. Will ask another question about it. – Ertai87 Aug 30 '12 at 06:25
  • Figured out how to use Fragments, and it worked! Thanks zapl! – Ertai87 Aug 31 '12 at 17:50

1 Answers1

0

I you are looking to dynamically change your layout then a LayoutInflater should be the way to go, similar to the tutorial you posted, but if you read the Inflater documentation, you should get a better sense of how it can be used.

Why not just create separate Activities for each Base? (If I understand what you are trying to do correctly)

EDIT from original question asker (since I can't seem to figure out how to add replies here): I read the documentation for LayoutInflater, but I couldn't quite understand how it worked. I tried using it as per that tutorial, but it didn't seem to work...can you be a bit more specific as to what needs to be done?

Ertai87
  • 1,156
  • 1
  • 15
  • 26
Tom
  • 340
  • 1
  • 7
  • Nevermind; had NoScript enabled so I couldn't respond properly; anyway, I put a response there for you. – Ertai87 Aug 30 '12 at 03:47