how to delete table row in table layout in android

前端 未结 8 2332
感动是毒
感动是毒 2021-02-13 01:28
void init()
{
   intcolumnwidth1 = int_scr_wd*55;
   intcolumnwidth1 = intcolumnwidth1/100;
   for (int i = 0; i < strarr.length-1; i++)
   {
      strinarr = fun1.sp         


        
相关标签:
8条回答
  • 2021-02-13 01:48

    look this code to remove row in table

    private List<View> listViewRow;
    
    if (listViewRow.size() > 0) {
        for (View view : listViewRow) {
            table.removeView(view);
        }
    }
    
    for (int i = 0; i < myList.size(); i++) {
        row.addView((new TextView(context).setText("Teste")), 0);
        row.addView((new TextView(context).setText("Teste")), 1);
        row.addView((new TextView(context).setText("Teste")), 2);
    
        listViewRow.add(row);
        table.addView(row, 1);
    }
    
    0 讨论(0)
  • 2021-02-13 01:55

    Use this:

    new Handler().postDelayed(new Runnable() {
          public void run() {
             TableRow row = (TableRow)table.getChildAt(i);
             table.removeView(row);
          }
     }, 100);
    

    Where i - is row position, wich you want to delete.

    0 讨论(0)
  • 2021-02-13 01:58

    You need to know the textview to be deleted. The TextView can be identified by setting a unique id using setId() or using a unique tag using setTag().

    It can then be identified by TextView tv = (TextView) tr1.findViewByTag(unique tag);

    Use removeView to delete the View.

    0 讨论(0)
  • 2021-02-13 01:58

    I use this:

    tl.removeView(tl.getChildAt(index));
    
    0 讨论(0)
  • 2021-02-13 01:59

    I realize this is a old thread but I as shocked when I came across this without a decent answer.

    I do it like this:

    TableLayout table = (TableLayout) findViewById(R.id.myTable);       
    table.removeAllViews();
    

    That will remove all of the child views, in this case rows and everything. It doesn't seem by your description that you want to delete just one row, but that you want to remove them and then load the rows again. The above code will do the removing part.

    0 讨论(0)
  • 2021-02-13 02:05

    Try removeView

    row = (TableRow)findViewById(R.id.row);
    table.removeView(row);
    
    0 讨论(0)
提交回复
热议问题