Application error after adding fragment

I am adding this https://github.com/rockerhieu/emojicon lib to my application. Now this library requires me to add a fragment to my layout

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

after adding this fraud in the app, could you help me solve this problem? here logit

Called: android.view.InflateException: binary line of XML file # 90: Error inflating class fragment

+4
source share
3 answers

You must use this to edit text.

<github.ankushsachdeva.emojicon.EmojiconEditText
        android:id="@+id/emojicon_edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_weight="8"
        emojicon:emojiconSize="28sp" />

and then in the class file after emojitext initialization you have to use these listeners

    final EmojiconsPopup popup = new EmojiconsPopup(rootView, this);
        //Will automatically set size according to the soft keyboard size
        popup.setSizeForSoftKeyboard();

        /*--------------------------------------------------------------------*/

        popup.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                changeEmojiKeyboardIcon(emojiButton, R.mipmap.smiley);
            }
        });

//If the text keyboard closes, also dismiss the emoji popup
        popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {

            @Override
            public void onKeyboardOpen(int keyBoardHeight) {

            }

            @Override
            public void onKeyboardClose() {
                if (popup.isShowing())
                    popup.dismiss();
            }
        });

       /*On emoji clicked, add it to edittext*/
        popup.setOnEmojiconClickedListener(new EmojiconGridView.OnEmojiconClickedListener() {

            @Override
            public void onEmojiconClicked(Emojicon emojicon) {
                if (emojiconEditText == null || emojicon == null) {
                    return;
                }

                int start = emojiconEditText.getSelectionStart();
                int end = emojiconEditText.getSelectionEnd();
                if (start < 0) {
                    emojiconEditText.append(emojicon.getEmoji());
                } else {
                    emojiconEditText.getText().replace(Math.min(start, end),
                            Math.max(start, end), emojicon.getEmoji(), 0,
                            emojicon.getEmoji().length());
                }
            }
        });

        //On backspace clicked, emulate the KEYCODE_DEL key event
        popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {

            @Override
            public void onEmojiconBackspaceClicked(View v) {
                KeyEvent event = new KeyEvent(
                        0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
                emojiconEditText.dispatchKeyEvent(event);
            }
        });


        // To toggle between text keyboard and emoji keyboard keyboard(Popup)
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                //If popup is not showing => emoji keyboard is not visible, we need to show it
                if (!popup.isShowing()) {

                    //If keyboard is visible, simply show the emoji popup
                    if (popup.isKeyBoardOpen()) {
                        popup.showAtBottom();
                        changeEmojiKeyboardIcon(emojiButton, R.mipmap.ic_action_keyboard);
                    }

                    //else, open the text keyboard first and immediately after that show the emoji popup
                    else {
                        emojiconEditText.setFocusableInTouchMode(true);
                        emojiconEditText.requestFocus();
                        popup.showAtBottomPending();
                        final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        inputMethodManager.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
                        changeEmojiKeyboardIcon(emojiButton, R.mipmap.ic_action_keyboard);
                    }
                }

                //If popup is showing, simply dismiss it to show the undelying text keyboard
                else {
                    popup.dismiss();
                }
            }
        });

Hope this helps you :)

0
source

<fragment> xml. <FrameLayout> :

FragmentManager manager = getSupportFragmentManager(); // or getFragmentManager() if you are not using android.support.v4.app.Fragment
manager.beginTransaction().replace(R.id.frame_layout, new EmojiconsFragment()).commit();
0

Your activity should implement these interfaces:

public class MainActivity extends Activity implements EmojiconGridFragment.OnEmojiconClickedListener, OnEmojiconBackspaceClickedListener{

and implement the method (in your activity):

    @Override
    public void onEmojiconClicked(Emojicon emojicon) {

    }

    @Override
    public void onEmojiconBackspaceClicked(View v) {

    }

It is very strange why this was not written in the readme library

0
source

Source: https://habr.com/ru/post/1614453/


All Articles