2014-07-10 69 views
-1

我正在開發一個android應用程序,我需要在發生事件時刷新表格。那是當用戶點擊一個按鈕時,表格現在應該改變顯示新的數據。所以我爲此使用了removeAllViews。然後,我會動態地將這些行添加到表中。發生的情況是,當行數小於以前的行數時,將顯示新行並在其下面顯示舊行。你能告訴我需要做什麼嗎?表格佈局不正常刷新 - Android

TableLayout tableLayout1;          
public void displayPanel1(int co) // dynamically add table 
{  
    LinearLayout ll = (LinearLayout)findViewById(R.id.asdf); 
    LayoutParams lp = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);    
    for(int i=0;i<co;i++) { 
     TableRow tR = new TableRow(this);  
     for(int j=0;j<12;j++) { 
      TextView tv2=new TextView(this); 
      tv2.setText(i+j+""+"\n"+"h"); 
      tR.addView(tv2);   
     } 
     tableLayout1.addView(tR);  
    } 
    ll.addView(tableLayout1, lp);   
}  

在點擊事件中,我寫了tableLayout1.removeAllViews();並再次調用displayPanel()函數

+0

你能告訴我們一些相關的代碼嗎?沒有看到你在做什麼,我們只能猜測問題可能是什麼。 –

+0

你使用任何主題?嘗試使佈局無效。 – Zeus

+0

我沒有使用任何主題。我也嘗試失效..但它仍然不工作:( – user2736177

回答

0

佈局被強烈地給出。在更改佈局時,它正在適當刷新。我改變了佈局到 TableLayout.LayoutParams parms = new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tableLayout1.setLayoutParams(parms);