I have an Activity which is resumed with
@Override
protected void onResume() {
Log.v(TAG, " onResume() disables the OK button");
// onAuthentificated will re-enable it
findViewById(android.R.id.button1).setEnabled(false);
super.onResume();
}
Later, the authentification is successful, and my callback is called
@Override
public void onAuthenticated(String username) {
Log.v(TAG, "user can press button");
findViewById(android.R.id.button1).setEnabled(true);
super.onAuthenticated(username);
}
I know that the setEnabled(true) is called last.
My problem is that the button remains greyed out. What’s happening and how can I fix this?
The layout(but it won’t help)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/VerticalLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- other stuff -->
<Button
android:id="@android:id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@android:string/ok" />
</LinearLayout>
Here are the last lines of logcat
08-30 13:00:45.182: V/ReportActivity(344): onResume() disables the OK button
8-30 13:00:45.382: I/ReportActivity(344): Authentification token callback
08-30 13:00:45.477: D/dalvikvm(344): GC_CONCURRENT freed 324K, 5% free 9960K/10375K, paused 2ms+3ms
08-30 13:00:45.567: D/NetworkService(344): Broadcast the fact user is authenticated
08-30 13:00:45.567: D/ReportActivity(344): user can press button
The solution is to store the result of
findViewById(android.R.id.button1)in a field that is initialized by theonResume()method.