问题
单击注销按钮后,某些操作有时不会执行。在下面的代码中,有时hideTabBar()
andshowAuth()
似乎没有被执行,但有时它们被执行了。为什么?
源代码
MainActivity.java
public void selectLogout(View view) {
AlertDialog.Builder mAlertDialogBuilder = new AlertDialog.Builder(this);
mAlertDialogBuilder.setTitle("Logout").setMessage("Are you sure you wanna logout?");
mAlertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
mAlertDialogBuilder.setPositiveButton("Logout", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mWebview.postDelayed(new Runnable() {
@Override
public void run() {
mWebview.loadUrl(WEB_BASE + LOGOUT_TAG);
btnSlide.performClick();
hideTabBar();
showAuth();
}
}, 500);
}
});
mAlertDialogBuilder.show();
}
activity_main.xml
android:onClick="selectLogout"
用于将回调函数绑定到onClick
注销按钮。
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="@color/button_state_resource"
android:clickable="true"
android:onClick="selectLogout" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:src="@drawable/icon_logout" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="120dp"
android:text="Logout" />
</RelativeLayout>