Dynamic layout question

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Dynamic layout question

Postby xdm87 » Wed Jan 06, 2010 7:59 am

I am making a layout (that looks a lot like the Settings app) and each of the main items in the scrollview will be dynamically generated.

Is there a way I can define the layout statically in XML then inject the dynamic items into the scrollview?

Thanks!
xdm87
Freshman
Freshman
 
Posts: 4
Joined: Tue Jan 05, 2010 6:19 am

Top

Postby jwei512 » Wed Jan 06, 2010 12:59 pm

Yea I assume you just mean in your XML you want to define something like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <TextView
  3.  
  4.      android:id="@+id/text_example"
  5.  
  6.      android:layout_height="wrap_content"
  7.  
  8.      android:layout_width="wrap_content" />
  9.  
  10.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


And in which case, to "dynamically" fill its contents, in your JAVA class, most likely in the onCreate method, you would want to do something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. TextView text = (TextView) findViewById(R.id.text_example);
  3.  
  4. text.setText("Hello World");
  5.  
  6.  
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


Make sense? So basically you statically define the structure of your layout in XML, and then in your JAVA you "find" all the views in your layout using the R.id, and once you find it you can set its value dynamically.

Hope this helped / what you were looking for.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests