1

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.

Stephanie Page
  • 3,875
  • 1
  • 18
  • 22
Soumya Simanta
  • 11,523
  • 24
  • 106
  • 161

2 Answers2

0

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.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
0

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().
Zack Marrapese
  • 12,072
  • 9
  • 51
  • 69
  • This is a reasonable approach. However, I'm still not clear about what's the best way to attach these views to to database tables so that the user can get data back for their custom created screens the next time they use their app. – Soumya Simanta Mar 28 '11 at 19:49
  • You could store the entire XML in a database xml column and retrieve it? Once you come up with an XML schema, it should be good to go right? – Tejaswi Yerukalapudi Mar 28 '11 at 20:13
  • Yes I can store the XML in the database (or on the file system). However, I still need to have some code that will access the actual data that will be displayed on these screens. In my example above, I need a data access layer to access name, location, picture, age etc. – Soumya Simanta Mar 29 '11 at 14:26