andoid 删除tablerow里某一项

    xiaoxiao2021-03-25  32

    tableRow = (TableRow) tableLayout.getChildAt(i); tableRow.removeViewAt(4); //此句删除此行第5列内容,如果循环,则删除整列. 也有removeAllView.......... 最近发现,要删除tablerowr的某列,在添加时要注意方法: 比如:我们通常添加列是: tableRow.addview(textview1);tableRow.addview(textview2);tableRow.addview(textview3); tableRow.addview(textview4);tableRow.addview(textview5);tableRow.addview(textview6);tableRow.addview(textview7); 当要删除某一列或某几列时,可以这样删:tableRow.removeViewAt(1);tableRow.removeViewAt(2);tableRow.removeViewAt(3);这样,看似正确,但是,不知是android studio的问题,还是本人没弄对,这样删完,再给删除的列更新内容时,会出现错误,新添加的列,是从之前的列(即第7列)后面添加的。比如,这样添加:tableRow.addView(textview1,1); 这一列,并不是添加到第一列,如何实现删除某一列,更新这一列内容呢? 方法是:在添加时,就为每一列添加列索引:tableRow.addview(textview1,1);tableRow.addview(textview2,2);tableRow.addview(textview3,3); tableRow.addview(textview4,4);tableRow.addview(textview5,5);tableRow.addview(textview6,6);tableRow.addview(textview7,7);
    转载请注明原文地址: https://ju.6miu.com/read-50418.html

    最新回复(0)