2013年9月5日星期四

Click TabHost android graphics pop PopupWindow election being given !


As shown above, when I click on more will pop up a PopupWindow, but always being given the wrong information is as follows :
05-02 03:13:22.999: E/AndroidRuntime(1404): FATAL EXCEPTION: main
05-02 03:13:22.999: E/AndroidRuntime(1404): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.view.ViewGroup.addView(ViewGroup.java:1865)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.view.ViewGroup.addView(ViewGroup.java:1845)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.widget.PopupWindow.preparePopup(PopupWindow.java:808)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.widget.PopupWindow.showAtLocation(PopupWindow.java:681)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at com.shuangchi.activity.MainActivity.openPopupWindow(MainActivity.java:209)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at com.shuangchi.activity.MainActivity.access$1(MainActivity.java:207)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at com.shuangchi.activity.MainActivity$1.onClick(MainActivity.java:88)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.view.View.performClick(View.java:2408)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.view.View$PerformClick.run(View.java:8816)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.os.Handler.handleCallback(Handler.java:587)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.os.Looper.loop(Looper.java:123)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at java.lang.reflect.Method.invokeNative(Native Method)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at java.lang.reflect.Method.invoke(Method.java:521)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-02 03:13:22.999: E/AndroidRuntime(1404):  at dalvik.system.NativeStart.main(Native Method)

code is as follows :


private void init()
{
//九宫格适配器
adapter = new GridViewAdapter(this, titles, imgIds);

//初始化GridView
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_morefunction, null);
gridView = (GridView) view.findViewById(R.id.gridview);
gridView.setAdapter(adapter);
//初始化PopupWindow
popupWindow = new PopupWindow(gridView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
}



private void event()
{
tabWidget.getChildAt(4).setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
parent = MainActivity.this.findViewById(android.R.id.tabhost);
openPopupWindow();
}
});
}



/***
 * 显示PopupWindow
 */
private void openPopupWindow()
{
popupWindow.showAtLocation(parent, Gravity.CENTER,0,0);
}

solve ah ! How can display properly, Jiji Ji !
------ Solution ---------------------------------------- ----
prompts you parenta obvious problem you can change the layout of other places to try to add the following to your PopupWindow
------ Solution ------ --------------------------------------

------ Solution ---------- ----------------------------------
viewgroup first removeallchilds, then add the child on it. Error is that the child already has a parent , and give him a parent will complain .
------ Solution ---------------------------------------- ----
 popupWindow = new PopupWindow(view, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable());

------ For reference only ---------------------------- -----------
come to that ! Come on people
------ For reference only ----------------------------------- ----
their top yourself !
------ For reference only -------------------------------------- -
parent I know there are problems, I hope the effect is PopupWindow displayed in TabHost on
------ For reference only ----------------- ----------------------
you initialize PopupWindow doing with GridView
------ For reference only ------ ---------------------------------

I want to display GridView in PopupWindow ah !
------ For reference only -------------------------------------- -
with demand

没有评论:

发表评论