我想從menuoptions中顯示popupdialogue對話框。代碼的存在 -無法顯示彈出式對話框
public void createNewList(){
popupCreateList = new PopupWindow(popupCreateListView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
popupCreateList.setBackgroundDrawable(new BitmapDrawable());
popupCreateList.setOutsideTouchable(true);
Log.i(TAG,"popUpListView-->>>" + popUpListView.getParent());
//((ViewGroup)popUpListView.getParent()).removeView(popUpListView); <--Commented
popupCreateList.showAtLocation(findViewById(R.id.layoutTaskManagerID), Gravity.CENTER, 0, 0); <-- ERROR
//popupCreateList.showAsDropDown(listsButton, 50, -30);
}
每當我嘗試運行它,它給了我下面的logcat錯誤 -
12-30 14:43:00.735: E/AndroidRuntime(1385): FATAL EXCEPTION: main
12-30 14:43:00.735: E/AndroidRuntime(1385): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.view.ViewGroup.addViewInner(ViewGroup.java:3378)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.view.ViewGroup.addView(ViewGroup.java:3249)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.view.ViewGroup.addView(ViewGroup.java:3225)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.widget.PopupWindow.preparePopup(PopupWindow.java:965)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:836)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:809)
12-30 14:43:00.735: E/AndroidRuntime(1385): at ray.kaushik.simple.task.manager.TaskManagerActivity.createNewList(TaskManagerActivity.java:340)
12-30 14:43:00.735: E/AndroidRuntime(1385): at ray.kaushik.simple.task.manager.TaskManagerActivity.onMenuItemSelected(TaskManagerActivity.java:324)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:958)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:468)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:126)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.view.View$PerformClick.run(View.java:16966)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.os.Handler.handleCallback(Handler.java:615)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.os.Handler.dispatchMessage(Handler.java:92)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.os.Looper.loop(Looper.java:137)
12-30 14:43:00.735: E/AndroidRuntime(1385): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-30 14:43:00.735: E/AndroidRuntime(1385): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 14:43:00.735: E/AndroidRuntime(1385): at java.lang.reflect.Method.invoke(Method.java:511)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-30 14:43:00.735: E/AndroidRuntime(1385): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-30 14:43:00.735: E/AndroidRuntime(1385): at dalvik.system.NativeStart.main(Native Method)
當我嘗試點擊第二次面對此錯誤。如果我取消註釋註釋行來刪除視圖仍然是相同的。可以dumone plz指導我與此原因。請詳細說明我新的android開發。任何想法相同。?感謝提前。
Ray
thnx兄弟..!我會試一下 ..!! – RayKaushik