2016-04-19 11 views
0

button.setEnabled(false);を呼び出して無効にしたAlertDialogpositiveボタンのクリックをリッスンします。無効なAlertDialogボタンのクリックをリッスンする

どうすればよいですか?これが不可能な場合は、既知の回避策がありますか?

PS。私がこれをやりたいのは、誰かがボタンを押すと、 "続ける前にこれをする必要がある"と言って乾杯をしたいのです。

+0

ユーザーが特定のタスクを完了するまで、ボタンを表示しないようにしてください。 – Eenvincible

+0

これはオプションですが、これはダイアログを理解しづらいものにしていますが、わかりやすく(トーストのヒントとともに)理解しやすくしたいと思っています。あなたの提案は、私が現時点で持っているもの(隠れているか無効になっているか)とまったく同じです。 – Timmiej93

+0

ボタンが無効になっているときにクリックをリッスンすることについてよくわかりません。ユーザーがタスクを完了しておらず、ボタンを無効にしていない場合は、トーストを表示することができます。 – Eenvincible

答えて

0

無効なボタンのクリックをリッスンする方法ではありません。これは回避策です。

私はボタンの色を変えることで、そのボタンが無効になっているように見せてくれました。あなたが何をしたいか

// Instantiate positive button 
    final Button posButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE); 

// Save the original button's background 
    final Drawable bg = posButton.getBackground(); 

// Set button's looks based on boolean 
    if (buttonDisabled) { 
     posButton.setTextColor(getResources().getColor(R.color.disabledButtonColor, null)); 
     // R.color.disabledButtonColor == #DBDBDB, which is pretty close to 
     // the color a disabled button gets. 
     posButton.setBackgroundColor(Color.TRANSPARENT); 
     // Color.TRANSPARENT makes sure all effects the button usually shows disappear. 
    } else { 
     posButton.setTextColor(getResources().getColor(R.color.colorPrimaryDark, null)); 
     // R.color.colorPrimaryDark is the color that gets used all around my app. 
     // It was the closest to the original for me. 
     posButton.setBackground(bg); 
     // bg is the background we got from the original button before. 
     // Setting it here also re-instates the effects the button should have. 
    } 

今、それを楽しんでいる、それは

やるべき
public void onClick(View v) { 
    if (buttonDisabled) { 
     // Button is clicked while it's disabled 
    } else { 
     // Button is clicked while it's enabled, like normal 
    } 
} 

「無効」だたびに、ボタンのアクションをキャッチすることを忘れないでください。

関連する問題