[TinyTut] - Dynamically add rows to TableLayout

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby Dayn » Thu Aug 06, 2009 12:40 pm

Hi
I take a listview and buttons inside a tab

but I can break both.

I try to use LinearLayout , TableRow .... but nothing are well for what I want
1 time my button move
2 time my list move also

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.         android:orientation="vertical"
  6.  
  7.         android:layout_height="fill_parent"
  8.  
  9.     android:layout_width="fill_parent" 
  10.  
  11.     android:background="@drawable/text_bleu">                          
  12.  
  13.          
  14.  
  15.     <ListView
  16.  
  17.                 android:id="@+id/listVoicemail"
  18.  
  19.                         android:layout_width="fill_parent"
  20.  
  21.                 android:layout_height="wrap_content"/>
  22.  
  23.                
  24.  
  25.         <Button
  26.  
  27.                         android:id="@+id/effacer"
  28.  
  29.                         android:layout_width="110px"
  30.  
  31.                         android:layout_height="50px"
  32.  
  33.                         android:text="Effacer"
  34.  
  35.                         android:textStyle="bold"
  36.  
  37.                         android:layout_x="180px"
  38.  
  39.                         android:layout_y="315px">
  40.  
  41.                 </Button>
  42.  
  43.        
  44.  
  45.                 <Button
  46.  
  47.                         android:id="@+id/repondre"
  48.  
  49.                         android:layout_width="110px"
  50.  
  51.                         android:layout_height="50px"
  52.  
  53.                         android:text="Répondre"
  54.  
  55.                         android:textStyle="bold"
  56.  
  57.                         android:layout_x="30px"
  58.  
  59.                         android:layout_y="315px">
  60.  
  61.                 </Button>
  62.  
  63.        
  64.  
  65. </AbsoluteLayout>
  66.  
  67.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


Help me to add the better "</...Layout>" please

Dayn
Attachments
Bouton_tab.JPG
Bouton_tab.JPG (28.21 KiB) Viewed 5472 times
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

Top

Postby Dayn » Fri Aug 07, 2009 9:00 am

Hi

And if I just add a ScrollView for my listview it dipslay the next picture.
And if I change android:layout_height="fill_parent" to android:layout_height="wrap_content" it's the same display.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.         android:orientation="vertical"
  6.  
  7.         android:layout_height="fill_parent"
  8.  
  9.     android:layout_width="fill_parent" 
  10.  
  11.     android:background="@drawable/text_bleu">                          
  12.  
  13.        
  14.  
  15.     <ScrollView
  16.  
  17.    android:orientation="vertical"
  18.  
  19.    android:layout_width="fill_parent"
  20.  
  21.    android:layout_height="fill_parent">  
  22.  
  23.          
  24.  
  25.         <ListView
  26.  
  27.                 android:id="@+id/listVoicemail"
  28.  
  29.                         android:layout_width="fill_parent"
  30.  
  31.                 android:layout_height="wrap_content"/>
  32.  
  33.                
  34.  
  35.     </ScrollView>              
  36.  
  37.                
  38.  
  39.         <Button
  40.  
  41.                         android:id="@+id/effacer"
  42.  
  43.                         android:layout_width="110px"
  44.  
  45.                         android:layout_height="50px"
  46.  
  47.                         android:text="Effacer"
  48.  
  49.                         android:textStyle="bold"
  50.  
  51.                         android:layout_x="180px"
  52.  
  53.                         android:layout_y="315px">
  54.  
  55.                 </Button>
  56.  
  57.        
  58.  
  59.                 <Button
  60.  
  61.                         android:id="@+id/repondre"
  62.  
  63.                         android:layout_width="110px"
  64.  
  65.                         android:layout_height="50px"
  66.  
  67.                         android:text="Répondre"
  68.  
  69.                         android:textStyle="bold"
  70.  
  71.                         android:layout_x="30px"
  72.  
  73.                         android:layout_y="315px">
  74.  
  75.                 </Button>
  76.  
  77.        
  78.  
  79. </AbsoluteLayout>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


I think I forget something but i don't found it.

Dayn
Attachments
Bouton_tab6.JPG
Bouton_tab6.JPG (25.19 KiB) Viewed 5463 times
User avatar
Dayn
Developer
Developer
 
Posts: 31
Joined: Thu Jul 09, 2009 10:45 am
Location: Paris and Dijon

Postby SalvoMaltese » Wed Sep 09, 2009 4:10 pm

Hi all

I can't see this code working

As output I only see "Static Button".

I start a blank project, replaced main.xml with that one provided by minusplus and added the java code after " setContentView(R.layout.main);" in the java file.

Any suggestion?
SalvoMaltese
Freshman
Freshman
 
Posts: 7
Joined: Wed Sep 09, 2009 4:07 pm

import mistake

Postby elmuSSo » Tue Sep 15, 2009 11:12 pm

SalvoMaltese wrote:Hi all

I can't see this code working

As output I only see "Static Button".

I start a blank project, replaced main.xml with that one provided by minusplus and added the java code after " setContentView(R.layout.main);" in the java file.

Any suggestion?


Mates. I had also this problem.

If using Eclipse as a compiler, when You want to use
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

it suggest to add
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.view.ViewGroup.LayoutParams;
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


But this is wrong import for TableRow. Insted, You should use:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.widget.TableRow.LayoutParams;
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


So just add this line to your imports and everything should work fine :)
elmuSSo
elmuSSo
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 15, 2009 3:18 am
Location: Poland

Remove buttons dynamically

Postby davidkebo » Thu Nov 19, 2009 8:02 pm

Does anybody knows how to remove buttons dynamically.
David Kebo
davidkebo
Freshman
Freshman
 
Posts: 6
Joined: Sun Nov 08, 2009 8:19 pm
Location: St. Louis, MO

Postby divestoclimb » Thu Nov 19, 2009 8:12 pm

divestoclimb - Android SCUBA app developer
Android Community | Gas Mixer, ScubaLib, Scuba Tanks | d2c Checklist
All code is open source under Apache license.
divestoclimb
Developer
Developer
 
Posts: 33
Joined: Mon May 11, 2009 7:46 pm

Top

Add listener

Postby davidkebo » Thu Nov 19, 2009 9:26 pm

The buttons are all created dynamically

Button b = new Button(this);

How do you add a listener to each button independently since they don't have a specific name ?
David Kebo
davidkebo
Freshman
Freshman
 
Posts: 6
Joined: Sun Nov 08, 2009 8:19 pm
Location: St. Louis, MO

Postby divestoclimb » Thu Nov 19, 2009 9:42 pm

If you want to add the listener right after the button is created, just call setOnClickListener() on b :)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. b.setOnClickListener(new Button.OnClickListener() {
  2.  
  3.   public void onClick(View v) {
  4.  
  5.     // Handle click
  6.  
  7.   }
  8.  
  9. });
  10.  
  11.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Otherwise, you'd either have to make the button object a class member variable so you can access it later, or assign an ID to it with setId() so you can call findViewById() and retrieve it.
divestoclimb - Android SCUBA app developer
Android Community | Gas Mixer, ScubaLib, Scuba Tanks | d2c Checklist
All code is open source under Apache license.
divestoclimb
Developer
Developer
 
Posts: 33
Joined: Mon May 11, 2009 7:46 pm

Position dynamic Objects

Postby gdomod » Thu Nov 19, 2009 10:14 pm

Hi want to set x,y positions to dynamic object.
anyone can get me an howto ?

its possible to set position also from bottom ?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private void drawButtons(FrameLayout fl){
  2.  
  3.                 Button b1 = new Button(this.HauptObjekt);
  4.  
  5.         b1.setText("Dynamic Button");
  6.  
  7.         b1.setLayoutParams(new LayoutParams(
  8.  
  9.                   LayoutParams.FILL_PARENT,
  10.  
  11.                   LayoutParams.WRAP_CONTENT));
  12.  
  13.        
  14.  
  15.        fl.addView(b1);
  16.  
  17.  
  18.  
  19.         }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
gdomod
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Nov 19, 2009 10:12 pm

Postby lordgarthon » Mon Dec 21, 2009 1:51 am

Does anyone know how I account for adding things to a specific column (I have 4 columns in my tablelayout), as well as spanning. Also, How do I account for adding to a specific row? In other words if I have 4 rows static, can I insert between rows 1 and 2? Is this possible? Thanks!
lordgarthon
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 21, 2009 1:48 am

Postby zehunter » Sun Jan 10, 2010 11:55 am

hi everyone,

i'm not exactly using the same code, but i get inspired by this one.

i can add button dynamicly, and delete them... but when i quit and restart application, all vanish :-(

so, i'm looking for a solution to save dynamic button, and to be able to recreate them when user quit the application, and restart it again...

thanks in advance for your help,
zehunter
Developer
Developer
 
Posts: 27
Joined: Sun Jan 10, 2010 10:45 am

Postby yusuf » Wed Feb 24, 2010 7:35 pm

We can implement using for loop??
Dynamically adding rows
Androiding.........................
yusuf
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Mon Feb 15, 2010 4:25 pm
Location: Pune,India

Postby gazzaaa87 » Wed Mar 03, 2010 12:28 pm

Yes does anyone know how to implement this within a for loop - if you have 50 rows you want to add it would be ugly to repeat these steps for each one.

Incidentally thank you elmuSSo - that solution fixed the problem most people had in this thread. It would have been nicer if the original poster had tested his own tutorial before posting.

Thanks.
gazzaaa87
Freshman
Freshman
 
Posts: 4
Joined: Wed Mar 03, 2010 11:16 am

How to know number of rows in the table layout

Postby pria » Wed Mar 10, 2010 11:06 am

Hello plusminus,

Is there any way through which I can know the number of Table Row inside the Table Layout? I want to dynamically keep on adding table rows and remove any one from middle. I am not sure how can I get the index of the row on which I will click.

Please help.

Thnx

Pria
pria
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Mar 02, 2010 1:37 pm
Location: Pune

Postby NetApex » Fri Mar 19, 2010 4:47 am

gazzaaa87 wrote:Incidentally thank you elmuSSo - that solution fixed the problem most people had in this thread. It would have been nicer if the original poster had tested his own tutorial before posting.

Thanks.


The tutorial was "Posted: Sat Jan 26, 2008" at the time of posting it did work. Things change over time and as such you have to make sure you read the date and understand that there may be differences. If it has been over two years, it is almost a guarantee that you will need to change a few things to make them work successfully. Once you get more familiar with Android though, you will feel good about being able to spot the changes that you need to make on your own and it will bring a smile to your face. (Right now I am at the smirk stage... not quite fully able to smile yet.)
NetApex
Freshman
Freshman
 
Posts: 7
Joined: Mon Dec 07, 2009 1:07 am
Location: Sylvania, Ohio

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests