CERCA
PER MODELLO
FullScreen Chatbox! :)

Utente del giorno: complicazio con ben 2 Thanks ricevuti nelle ultime 24 ore
Utente della settimana: 9mm con ben 11 Thanks ricevuti negli ultimi sette giorni
Utente del mese: 9mm con ben 34 Thanks ricevuti nell'ultimo mese

Visualizzazione dei risultati da 1 a 2 su 2
Discussione:

Aggiungere righe a un TableLayout da codice - problema

Se questa discussione ti è stata utile, ti preghiamo di lasciare un messaggio di feedback in modo che possa essere preziosa in futuro anche per altri utenti come te!
  1. #1
    Baby Droid


    Registrato dal
    Aug 2009
    Messaggi
    11

    Ringraziamenti
    0
    Ringraziato 0 volte in 0 Posts
    Predefinito

    Aggiungere righe a un TableLayout da codice - problema

    Salve a tutti,

    ho provato ad usare il tutorial su [TinyTut] - Dynamically add rows to TableLayout :: anddev.org - Android Development Community | Android Tutorials per aggiungere righe a un TableLayout da codice.

    Adesso il mio file .java è così:
    codice:
    package com.ProgGrid;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.Button;
    import android.widget.TableLayout;
    import android.widget.TableRow;
    
    public class ProgGrid extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            /* Find Tablelayout defined in main.xml */ 
            TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout); 
                 /* Create a new row to be added. */ 
                 TableRow tr = new TableRow(this); 
                 tr.setLayoutParams(new LayoutParams( 
                                LayoutParams.FILL_PARENT, 
                                LayoutParams.WRAP_CONTENT)); 
                      /* Create a Button to be the row-content. */ 
                      Button b = new Button(this); 
                      b.setText("Dynamic Button"); 
                      b.setLayoutParams(new LayoutParams( 
                                LayoutParams.FILL_PARENT, 
                                LayoutParams.WRAP_CONTENT)); 
                      /* Add Button to row. */ 
                      tr.addView(b); 
            /* Add row to TableLayout. */ 
                  tl.addView(tr,new TableLayout.LayoutParams( 
                      LayoutParams.FILL_PARENT, 
                      LayoutParams.WRAP_CONTENT));
            setContentView(tl);
       }
    }
    mentre il main.xml è così:

    codice:
    <?xml version="1.0" encoding="utf-8"?> 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/myTableLayout" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 
         <TableRow 
              android:layout_width="fill_parent" 
              android:layout_height="wrap_content"> 
               
              <Button android:text="Static Button" android:id="@+id/myButton"/> 
         </TableRow> 
    </TableLayout>
    Solo che quando lancio il programma sull'emulatore, vedo solo lo "Static Button".

    Dov'è che sbaglio?

  2.  
  3. #2
    gnk
    gnk non è in linea
    Baby Droid


    Registrato dal
    Sep 2009
    Messaggi
    2

    Ringraziamenti
    0
    Ringraziato 0 volte in 0 Posts
    Predefinito

    Non va bene:

    b.setLayoutParams(new LayoutParams(
    LayoutParams.FILL_PARENT,
    LayoutParams.WRAP_CONTENT));

    ma deve essere:

    b.setLayoutParams(new TableRow.LayoutParams(
    LayoutParams.FILL_PARENT,
    LayoutParams.WRAP_CONTENT));

Discussioni simili

  1. codice fiscale per hero
    Da giobbe06 nel forum HTC Hero
    Risposte: 0
    Ultimo messaggio: 18-11-09, 11:27
  2. Aggiungere dizionario italiano ad una mod
    Da lepitrust nel forum HTC Magic
    Risposte: 1
    Ultimo messaggio: 14-08-09, 11:46
  3. aggiungere tag exif alle foto scattate
    Da moovida nel forum Problemi con l'sdk
    Risposte: 2
    Ultimo messaggio: 14-06-09, 18:05
  4. Richiesta codice sorgente
    Da edenroz nel forum Le Applicazioni per Android
    Risposte: 2
    Ultimo messaggio: 13-06-09, 22:03
  5. aggiungere apps al firmware direttamente in [update.zip]
    Da federico nel forum HTC Dream / Tmobile G1
    Risposte: 10
    Ultimo messaggio: 03-05-09, 23:22

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire risposte
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Torna su
Privacy Policy