Creating screens and underlying data access layer

2019-06-01 03:47发布

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 set 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.

2条回答
时光不老,我们不散
2楼-- · 2019-06-01 03:52

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().
查看更多
你好瞎i
3楼-- · 2019-06-01 04:08

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.

查看更多
登录 后发表回答