Approach for changing edittext to dropdowns at runtime?
what would be a good approach for the following?
EditText
EditText EditTextthe above three edit texts are how I have my xml layout. Depending on the users settings up on the server.. these edittexts need to be changed to a dropdown.
so for dropdowns if field1 is false field2 is true and field3 is false it would look like
EditText
DropDown EditTextShould I
- do it all programatically at runtime, removing existing views from xml and putting an开发者_运维问答 empty ViewGroup in its place
- have both options for each field in xml, and only show valid one (seems inefficient)
- some other approach I havent thought of
I might use ViewStubs. The view isn't inflated until you do it. You would have 6 ViewStubs but only 3 would get inflated at RunTime.
you can put both edittext and dropdown on a FrameLayout, with edit text being in front. then, on edit activation or any other logic - you can switch them... same thing can be done with ViewFlipper, etc.
精彩评论