开发者

Creating screens and underlying data access layer dynamically on Android

I want to allow the user to create "custom screens" dynamically by selecting from a existing set of fields at runtime i.e., everything should be done on App on the phone.

For example - existing se开发者_开发百科t of fields = {name, location, picture, age}.

User A wants to create a new screen with fields name, location and age.

and User B wants to have a screen with only name and picture.

These screens should be persistent and should be able to save, query and edit information in a local database on the phone.

Any help about how to achieve this in Android will be appreciated.

Thanks.


You will want to create these views dynamically in Java (not using layouts). I would put together some sort of XML schema, and then save it either in the DB or on the device. Then you could do things such as:

//pseudo-code
while (xmlDoc isn't empty) {
View v = null;
if (XML says to create a text view) {
    v = new TextView(this);
    ...
}
else if (XML says to create an ImageView) {
    v = new ImageView(this);
    ...
}
add v to the LinearLayout or whatever type of root view will be passed to setContentView().


Create a PreferenceScreen and add some boolean preferences with the names of your fields. So, every user can configure which fields to show in your data activity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜