0

我想删除一个活动的按钮,但是当我开始它时:

Intent inte = new Intent(PasswordConfirmationActivity.this, IndexActivity.class); UserAuthentication UA = new UserAuthentication(); control = UA.UserControl(EdtText.getText().toString()); inte.putExtra("confirmation", control); startActivity(inte); finish();

它给了我错误。
当另一个活动正在运行时,该活动也正在运行。

这就是我删除按钮的代码:

Boolean loginControl = getIntent().getBooleanExtra("confirmation",false);
    if (loginControl == true) {
        ViewGroup layout = (ViewGroup) ButtonClick2.getParent();
        if(null!=layout) 
        layout.removeView(ButtonClick2);
    }

这是 loccat :

08-13 15:37:13.676: E/WindowManager(17128): Activity tr.com.turkcell.shmobile.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@421bfcb0 that was originally added here
08-13 15:37:13.676: E/WindowManager(17128): android.view.WindowLeaked: Activity tr.com.turkcell.shmobile.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@421bfcb0 that was originally added here
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.Window$LocalWindowManager.addView(Window.java:549)
08-13 15:37:13.676: E/WindowManager(17128):     at android.app.Dialog.show(Dialog.java:277)
08-13 15:37:13.676: E/WindowManager(17128):     at android.app.ProgressDialog.show(ProgressDialog.java:116)
08-13 15:37:13.676: E/WindowManager(17128):     at android.app.ProgressDialog.show(ProgressDialog.java:99)
08-13 15:37:13.676: E/WindowManager(17128):     at android.app.ProgressDialog.show(ProgressDialog.java:94)
08-13 15:37:13.676: E/WindowManager(17128):     at tr.com.turkcell.shmobile.MainActivity$GetProduts.onPreExecute(MainActivity.java:188)
08-13 15:37:13.676: E/WindowManager(17128):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
08-13 15:37:13.676: E/WindowManager(17128):     at android.os.AsyncTask.execute(AsyncTask.java:534)
08-13 15:37:13.676: E/WindowManager(17128):     at tr.com.turkcell.shmobile.MainActivity$1$1.run(MainActivity.java:59)
08-13 15:37:13.676: E/WindowManager(17128):     at android.app.Activity.runOnUiThread(Activity.java:4591)
08-13 15:37:13.676: E/WindowManager(17128):     at tr.com.turkcell.shmobile.MainActivity$1.onClick(MainActivity.java:56)
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.View.performClick(View.java:4084)
08-13 15:37:13.676: E/WindowManager(17128):     at android.view.View$PerformClick.run(View.java:16966)
08-13 15:37:13.676: E/WindowManager(17128):     at android.os.Handler.handleCallback(Handler.java:615)
08-13 15:37:13.676: E/WindowManager(17128):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-13 15:37:13.676: E/WindowManager(17128):     at android.os.Looper.loop(Looper.java:137)
08-13 15:37:13.676: E/WindowManager(17128):     at android.app.ActivityThread.main(ActivityThread.java:4754)
08-13 15:37:13.676: E/WindowManager(17128):     at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:37:13.676: E/WindowManager(17128):     at java.lang.reflect.Method.invoke(Method.java:511)
08-13 15:37:13.676: E/WindowManager(17128):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-13 15:37:13.676: E/WindowManager(17128):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-13 15:37:13.676: E/WindowManager(17128):     at dalvik.system.NativeStart.main(Native Method)
08-13 15:37:15.266: D/ActivityThread(17128): handleResumeActivity now pri:0
08-13 15:37:15.266: D/ActivityThread(17128): handleResumeActivity set pri:0
08-13 15:37:17.086: D/AndroidRuntime(17128): Shutting down VM
08-13 15:37:17.086: W/dalvikvm(17128): threadid=1: thread exiting with uncaught exception (group=0x41b6a318)
08-13 15:37:17.086: E/AndroidRuntime(17128): FATAL EXCEPTION: main
08-13 15:37:17.086: E/AndroidRuntime(17128): java.lang.RuntimeException: Unable to start activity ComponentInfo{tr.com.turkcell.shmobile/tr.com.turkcell.shmobile.IndexActivity}: java.lang.NullPointerException
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.os.Looper.loop(Looper.java:137)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.ActivityThread.main(ActivityThread.java:4754)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at java.lang.reflect.Method.invoke(Method.java:511)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at dalvik.system.NativeStart.main(Native Method)
08-13 15:37:17.086: E/AndroidRuntime(17128): Caused by: java.lang.NullPointerException
08-13 15:37:17.086: E/AndroidRuntime(17128):    at tr.com.turkcell.shmobile.IndexActivity.onCreate(IndexActivity.java:75)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.Activity.performCreate(Activity.java:5008)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
08-13 15:37:17.086: E/AndroidRuntime(17128):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
4

2 回答 2

0

use view.setVisibility(View.Gone); it will remove the button from the screen.

    e.g:

    Boolean loginControl = getIntent().getBooleanExtra("confirmation",false);
    if (loginControl) {
        ViewGroup layout = (ViewGroup) ButtonClick2.getParent();
        toBeRemovedButton.setVisibility(View.Gone);
    }

To restart the current activity you can simply finish and recreate it using intent as usual. but remember after recreation, the oncreate() will be called again and the layout will be refreshed including views that you might have removed.

于 2013-08-13T12:53:26.713 回答
0

在完成()一个活动之后,您可以使用一个额外的 Bundle 来绘制它以隐藏按钮。

于 2013-08-13T12:57:50.743 回答