2010-09-10 74 views
0

我有一些問題,我無法解決這個問題。 在我的代碼中添加動態ImageButtons(我動態創建TableRow並添加到行),它們顯示出來,但我不能點擊它們(我嘗試所有,設置clickable爲true,啓用true和無)。如果我使用Button而不是ImageButton,所有工作都很好,除非我再次爲按鈕設置相同的背景。ANDROID - DYNAMMICALLY ADDVIEW PROBLEM

另外我從代碼中添加TextView,但TextView根本不顯示。 任何解決方案?

+0

你可以顯示你動態添加圖片按鈕的代碼片段嗎? – 2010-09-10 16:17:31

+0

我放下了不起作用的代碼。幫幫我 ? :( – msretractor 2010-09-10 21:11:44

回答

0

這是從一些名單

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; 
} 

有我添加創建行功能ImageButtons-這是在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)); 
} 

我TableLayout是其他的LinearLayout裏面,使不同?
謝謝