create several textviews with for...next statement

Put your problem here if it does not fit any of the other categories.

create several textviews with for...next statement

Postby travisjames » Sun Apr 12, 2009 9:39 pm

Can someone show me how to create several textviews in a for....next statement?

Such as:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. For (Status status "in" Statuses)
  2.  
  3. Create textviews here
  4.  
  5. Next ?
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


And is there anytthing else I need to do? Like in main.xml or something?
This will be creating several different textviews.
travisjames
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 02, 2009 10:00 pm
Location: Cordova, Tennessee

Top

Postby stifry » Mon Apr 13, 2009 4:50 pm

It's a lot easier to create your TextViews in your layout (like main.xml) unless you have a specific reason to create them programmitcally. But if you really want to do it, you might do something like this within your FOR loop:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. //name value layout is top
  3.  
  4.             RelativeLayout nameValueLayout = new RelativeLayout(activity);
  5.  
  6.             addView( nameValueLayout);  
  7.  
  8.            
  9.  
  10.             //name view
  11.  
  12.             RelativeLayout.LayoutParams nameParams =
  13.  
  14.                 new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  15.  
  16.             nameParams.setMargins(1, 1, 1, 1);
  17.  
  18.             nameParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  19.  
  20.            
  21.  
  22.             TextView nameView = new TextView( activity );
  23.  
  24.             nameView.setText( name );
  25.  
  26.             nameView.setTextSize(14f);
  27.  
  28.             nameView.setTextColor(Color.WHITE);
  29.  
  30.             nameValueLayout.addView(nameView);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Visit Trackaroo.com!
Trackmaster - Motorsports Lap Timer
Dynomaster - Performance Dyno
Image Image
User avatar
stifry
Developer
Developer
 
Posts: 46
Joined: Tue Feb 17, 2009 7:50 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 27 guests