1

以下のリンクに記載されているコードを使用して「一括無効化」ボタンを試してみましたが、完全に正常に動作します。ただし、同じコードは大量有効化には機能しません。

Android: 一括有効化/無効化ボタン

無効にするためのコード (作業中)

TableLayout tl = (TableLayout)findViewById(R.id.table1); // 
ArrayList<View> touchables = tl.getTouchables();
for(View touchable : touchables){
if( touchable instanceof Button && touchable != btnNewWord )
((Button)touchable).setEnabled(false);
}

有効にするためのコード (機能しない)

btnNewWord.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

TableLayout tl = (TableLayout)findViewById(R.id.table1);  
ArrayList<View> touchables = tl.getTouchables();
for(View touchable : touchables){
if( touchable != btnNewWord )
((Button)touchable).setEnabled(true);
}                       
4

1 に答える 1

3

ボタンを無効に設定すると、ボタンに触れることができなくなると思います。したがって、コード内のそのポイントを変更し、他の何かを使用してすべてのビューを取得する必要があります。ボタンを無効にするために使用したものを保持してArrayListから、同じものを使用してボタンを再度有効にすることができます。

編集 :

これを試して:

ArrayList<View> touchables //declare globaly

それから

TableLayout tl = (TableLayout)findViewById(R.id.table1); // 
touchables = tl.getTouchables();
for(View touchable : touchables)
{
    if( touchable instanceof Button && touchable != btnNewWord )
      ((Button)touchable).setEnabled(false);
}

そして今、

btnNewWord.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {

       for(View touchable : touchables)
       {
          if( touchable != btnNewWord )
            ((Button)touchable).setEnabled(true);
       }  
   }
}                     
于 2011-10-18T06:11:35.157 に答える