0

I'm working on showing emoji in popup window just like whatsapp from this library. I have created a popup window to show it in main activity. On click of button I made the following code

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);
            }
        });

The popup_item contain the following

<?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>

it is showing the following error.

   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)

I found that the reason for it is the nested fragment. But don't know the solution for it. Please help on this. I really need to solve this. I'm new to android. Thanks.

user2955143
  • 177
  • 4
  • 12
  • Do you already use fragment with this id in your application early? Also, why don't you use DialogFragment instead of PopupWindow? – Dimmerg Jan 24 '14 at 07:45
  • @Dimmerg: Will dialogfragment make the activity to resize automatically? – user2955143 Jan 24 '14 at 07:57
  • Sorry, don't understand. Resize for what, on rotation? – Dimmerg Jan 24 '14 at 07:59
  • @Dimmerg: I mean to say, if I give the gravity of the popup window as bottom, then the mainactivity layout will automatically resize. I tried with dialogfragment and it didn't. And also it is more complex to implement. – user2955143 Jan 24 '14 at 08:08
  • Ok, try to look at this http://stackoverflow.com/questions/8044593/properly-creating-a-fragment-in-a-popupwindow – Dimmerg Jan 24 '14 at 08:13
  • @Dimmerg: I need a suggestion. How the whatsapp showing the emoji in there application. Please tell me a tutorial for that. Please. – user2955143 Jan 24 '14 at 08:13
  • @user2955143 I also faced this issue. What i did is just copied the package name from the library `com.rockerhieu.emojicon` and again pasted before the `EmojiconsFragment` in the xml. Try out this `class="com.rockerhieu.emojicon.EmojiconsFragment"` and clean your project. – GrIsHu Jan 24 '14 at 09:15
  • @GrIsHu: I tried your suggestion. But didn't help. It works fine if I try to get the fragment on main activity. It only gives error if I try to get it inside popup window. I also pasted the whole logcat. – user2955143 Jan 24 '14 at 11:58

0 Answers0