2014-07-18 26 views
0

這是我的代碼,它在運行時生成動態按鈕! 我試了很多,但無法刪除以前創建的動態按鈕!Android - 如何刪除表格佈局以及其中的所有圖像?

這是代碼

TableLayout table = (TableLayout)findViewById(R.id.tableForButtons); 
    TableRow tableRow = new TableRow (this); 
    tableRow.setLayoutParams(new TableLayout.LayoutParams(
      TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT,1.0f 
      )); 
    table.setId(123); 
    table.addView(tableRow); 


    for(int i=0 ; i<ans_length; i++) 
    { 
     ImageView button = new ImageView (this); 
     button.setLayoutParams(new TableRow.LayoutParams(
       TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT,1.0f 
       )); 
     button.setImageResource(R.drawable.a); 
     button.setId(i); 
     tableRow.addView(button); 
    } 

請幫我這一點,併爲我提供這可能與它的所有視圖刪除此表佈局的代碼!

+0

你是否嘗試做任何刪除,你會分享嗎? – Tugrul

+0

可能的[在Android中動態添加和刪除視圖?]的副本(http://stackoverflow.com/questions/3995215/add-and-remove-views-in-android-dynamically) – Setu

+0

有一段時間在底部行正確的。節省必須做班次1。 – stark

回答

0

您需要撥打.removeAllViewsInLayout();以查看要刪除的視圖的根佈局。因此,例如table.removeAllViewsInLayout();應刪除所有行,但不會刪除表對象視圖。

相關問題