弹出窗口中膨胀库中的illegalargumentexception

时间:2014-01-24 07:43:30

标签: android android-fragments

我正在弹出窗口中显示表情符号,就像来自this库的whatsapp一样。我创建了一个弹出窗口,在主要活动中显示它。点击按钮后,我制作了以下代码

button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                View popUp = getLayoutInflater().inflate(R.layout.popup_item, null);
                window = new PopupWindow(getApplicationContext());
                window = new PopupWindow(popUp,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,true);
                window.setAnimationStyle(android.R.style.Animation_Activity);
                window.showAtLocation(popUp, Gravity.BOTTOM, 0, 0);
                window.setFocusable(true);
                window.setOutsideTouchable(true);
            }
        });

popup_item包含以下内容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:emojicon="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context="com.rockerhieu.emojicon.example.MainActivity$PlaceholderFragment" >

    <com.rockerhieu.emojicon.EmojiconTextView
        android:id="@+id/txtEmojicon"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <com.rockerhieu.emojicon.EmojiconEditText
        android:id="@+id/editEmojicon"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        emojicon:emojiconSize="28sp" />

    <fragment
        android:id="@+id/emojicons"
        android:layout_width="fill_parent"
        android:layout_height="220dp"
        class="com.rockerhieu.emojicon.EmojiconsFragment" />

</LinearLayout>

显示以下错误。

   01-24 01:07:25.245: E/AndroidRuntime(5420): FATAL EXCEPTION: main
01-24 01:07:25.245: E/AndroidRuntime(5420): android.view.InflateException: Binary XML file line #21: Error inflating class fragment
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at com.example.popupemoji.MainActivity$1.onClick(MainActivity.java:29)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.View.performClick(View.java:4204)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.View$PerformClick.run(View.java:17355)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.os.Handler.handleCallback(Handler.java:725)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.os.Looper.loop(Looper.java:137)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at java.lang.reflect.Method.invoke(Method.java:511)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at dalvik.system.NativeStart.main(Native Method)
01-24 01:07:25.245: E/AndroidRuntime(5420): Caused by: java.lang.IllegalArgumentException: Binary XML file line #21: Duplicate id 0x7f080000, tag null, or parent id 0x0 with another fragment for com.rockerhieu.emojicon.EmojiconsFragment
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
01-24 01:07:25.245: E/AndroidRuntime(5420):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)

我发现它的原因是嵌套片段。但不知道解决方案。请帮忙。我真的需要解决这个问题。我是android的新手。感谢。

0 个答案:

没有答案