2010-09-10 13 views
0

J'ai un problème et je ne peux pas résoudre ce problème. Dans mon code j'ajoute dynamiquement ImageButtons (je crée dynamiquement TableRow et ajouter dans la ligne), ils apparaissent mais je ne peux pas cliquer dessus (j'essaie tout, cliquable sur true, activé sur true et rien). Si j'utilise Button à la place ImageButton tout fonctionne bien sauf quand je mets à nouveau le même problème en arrière-plan pour les boutons.ANDROID - PROBLÈME DYNAMMIQUEMENT ADDVIEW

Aussi, j'ajoute TextView à partir du code mais TextView n'apparaît pas du tout. Toute solution pls?

+0

Pouvez-vous afficher l'extrait de code dans lequel vous ajoutez dynamiquement des boutons d'image? –

+0

Je pose du code qui ne fonctionne pas. Aidez-moi ? :( – msretractor

Répondre

0

Ceci est fonction pour créer des lignes, d'une liste

public static TableRow[] Create(List<Apartment> list){ 
    TableRow[] rows=null; 
    try{ 
     rows=new TableRow[list.size()*3]; 
     int i=0; 

     for(Apartment ap : list){ 
      rows[3*i]=new TableRow(activity); 
      rows[3*i+1]=new TableRow(activity); 
      rows[3*i+2]=new TableRow(activity); 

      rows[3*i].setLayoutParams(new LayoutParams( 
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 
      rows[3*i+1].setLayoutParams(new LayoutParams( 
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 
      rows[3*i+2].setLayoutParams(new LayoutParams( 
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 

      EditText txtMainInform=new EditText(activity); 

      //txtMainInform.setText(ap.GetMainInformation()); 
      txtMainInform.setLayoutParams(new LayoutParams( 
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 
      txtMainInform.setText("vvvvvvvvvvvvvvvvvvvv"); 
      txtMainInform.setVisibility(1); 
      rows[3*i].addView(txtMainInform); 
      rows[3*i].setVisibility(1); 

      TextView txtMoreInform=new TextView(activity); 
      txtMoreInform.setLayoutParams(new LayoutParams( 
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 
      rows[3*i+1].addView(txtMoreInform); 


      ImageButton imbGallery=new ImageButton(activity); 
      imbGallery.setClickable(true); 
      imbGallery.setEnabled(true); 
      imbGallery.setBackgroundResource(R.drawable.gallery_icon); 



      ImageButton imbCall=new ImageButton(activity); 
      imbCall.setBackgroundResource(R.drawable.phone); 

      ImageButton imbMap=new ImageButton(activity); 
      imbMap.setBackgroundResource(R.drawable.map); 
      rows[3*i+2].addView(imbGallery); 
      rows[3*i+2].addView(imbCall); 
      rows[3*i+2].addView(imbMap); 
      rows[3*i+2].setEnabled(true); 
      i++; 
     } 

    } 
    catch(Exception e){ 

    } 
    return rows; 
} 

Il ajouter ImageButtons- cela fait partie de la fonction OnCreate

TableRow[] rows=ResultCreator.Create(list); 
TableLayout table=(TableLayout)this.findViewById(R.id.result_layout); 

for(TableRow row:rows){ 
table.addView(row,new TableLayout.LayoutParams(
    LayoutParams.WRAP_CONTENT, 
    LayoutParams.WRAP_CONTENT)); 
} 

Mon TableLayout est à l'intérieur d'autres LinearLayout, faire la différence?
Merci