Attaullah Attaullah - 19 days ago 6
Android Question

Pop up Arabic/Urdu custom keyboard on Edittext Issue

I am working on app where i use Urdu Custom Keyboard its work fine but the problem is that when i type any-word e.g. (سلام), cursor become not works at mid character for example cut/copy/paste or deleting (ا) character from the mid from word are not work.
i uses rough technique just appending characters but is also work fine.

For taping any alphabetic

private void addText(View v) {
// String b = "";
// b = (String) v.getTag();
// urdu_word.setText(b);
if (isEdit == true) {
String b = "";
b = (String) v.getTag();
if (b != null) {
Log.i("buttonsOnclick", b);
// adding text in Edittext
mEt.append(b);
}
}
}


For back button tapping

private void isBack(View v) {
if (isEdit == true) {
CharSequence cc = mEt.getText();
if (cc != null && cc.length() > 0) {
{
mEt.setText("");
mEt.append(cc.subSequence(0, cc.length() - 1));
}
}
}
}


Here the screenshot clear my problem to you people
enter image description here

I used a lot of library and code from github but don't catch good idea

1) Keyboard-1
enter image description here

2) Keyboard-2
enter image description here

3) Keyboard-3
enter image description here

4) Keyboard-4

i checked all these keyboard and more from libs, have same cursor issue, how to manage fully my custom keyboard by deleting character from mid and copy my written text copy paste like normal keyboard with EditText, thanks in advance all of you :)

enter image description here

Answer

Thanks God i solved my issue using simple logic.

For back button

private void isBack(View v) {
        // char[] tempChar = null;
        if ((mEt.getText().toString().length() > 0)) {
            int temp = mEt.getSelectionEnd() - 1;
            if (temp >= 0) {
                mEt.setText((mEt.getText().toString()
                        .substring(0, mEt.getSelectionEnd() - 1).concat(mEt
                        .getText()
                        .toString()
                        .substring(mEt.getSelectionEnd(),
                                mEt.getText().length()))));
                mEt.setSelection(temp);
            }
        }
    }

For adding any character

private void addText(View v) {
        int temp = mEt.getSelectionEnd();
        if (temp >= 0) {
            String b = "";
            b = (String) v.getTag();

            mEt.setText((mEt.getText().toString()
                    .substring(0, mEt.getSelectionEnd()) + b.concat(mEt
                    .getText().toString()
                    .substring(mEt.getSelectionEnd(), mEt.getText().length()))));
            mEt.setSelection(temp + 1);
        }
    } 

for copy paste i added few lines code to EditText

    <EditText
        android:id="@+id/xEt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@drawable/edittextshape"
        android:ems="10"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="top"
        android:imeOptions="actionDone"
        android:padding="15dp"
        android:singleLine="false"
        android:visibility="visible" />