TableLayout ですべての TableRow を取得する方法を何時間も探していました。行を動的に追加および削除する方法は既に知っていますが、すべての行をループして、それらの一部を選択的に削除する必要があります。
回避策を思い付くことができると思いますが、アプリでの雑なハッキングを回避しようとしています。
TableLayout ですべての TableRow を取得する方法を何時間も探していました。行を動的に追加および削除する方法は既に知っていますが、すべての行をループして、それらの一部を選択的に削除する必要があります。
回避策を思い付くことができると思いますが、アプリでの雑なハッキングを回避しようとしています。
それぞれと を使っgetChildCount()
てみgetChildAt(int)
ましたか?
ループではかなり簡単なはずです:
for(int i = 0, j = table.getChildCount(); i < j; i++) {
View view = table.getChildAt(i);
if (view instanceof TableRow) {
// then, you can remove the the row you want...
// for instance...
TableRow row = (TableRow) view;
if( something you want to check ) {
table.removeViewAt(i);
// or...
table.removeView(row);
}
}
}
他のタイプのビューがある場合
TableLayout layout = (TableLayout) findViewById(R.id.IdTable);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof TableRow) {
TableRow row = (TableRow) child;
for (int x = 0; x < row.getChildCount(); x++) {
View view = row.getChildAt(x);
view.setEnabled(false);
}
}
}
私はしばらく同じものを探していました。私にとっては、テーブル レイアウトでビューを確認する方法を探していました。私はこれをしました:
//This will iterate through your table layout and get the total amount of cells.
for(int i = 0; i < table.getChildCount(); i++)
{
//Remember that .getChildAt() method returns a View, so you would have to cast a specific control.
TableRow row = (TableRow) table.getChildAt(i);
//This will iterate through the table row.
for(int j = 0; j < row.getChildCount(); j++)
{
Button btn = (Button) row.getChildAt(j);
//Do what you need to do.
}
}
for(int i = 0, j < table.getChildCount(); i < j; i++){
// then, you can remove the the row you want...
// for instance...
TableRow row = (TableRow) table.getChildAt(i);
if( something you want to check ) {
removeViewAt(i);
// or...
removeView(row);
}
}