开发者

how to dynamic load two different layout based on condition in android code

开发者 https://www.devze.com 2023-03-27 18:50 出处:网络
I have a small project, which will require the one android application be used by different group. For example: one group is the regular user, an开发者_高级运维other group is the admin user.

I have a small project, which will require the one android application be used by different group.

For example: one group is the regular user, an开发者_高级运维other group is the admin user.

My question is, if I like to create one similar UI android application, how to dynamically load the layout based on different condition (condition may be embedded in the local sqlite database), and move forward, the same condition will be kept, and the layout will be slightly different for different group of users.


as Android uses Java I believe that actually your problem is an exact match for an Abstract Factory implementation. Take a look at Abstract Factory Design Pattern. I believe that is what you need.

http://en.wikipedia.org/wiki/Abstract_factory_pattern

http://www.oodesign.com/abstract-factory-pattern.html

http://www.mydeveloperconnection.com/html/gof_design_patterns.htm

regards. []s


The code is the same, just different layouts? I would simply inflate different layouts depending on your condition.

Just a fast shot:

  • res/layout/group01_main.xml
  • res/layout/group02_main.xml ...
  • res/layout-land/group01_main.xml
  • res/layout-land/group02_main.xml ...

And in your activities setContentView() to the correct one.

0

精彩评论

暂无评论...
验证码 换一张
取 消