There is an EditText that behaves strangely, when typing, the characters in it are added not left to right, but from right to left (as if the text is typed in Arabic). I did not expose anywhere that the printing of symbols should be from the right to the left, what could be the problem?

Xml code:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="8dp" > <TextView android:id="@+id/tvWorkItemNumber" android:text="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginRight="20dp" android:layout_marginLeft="7dp" android:textSize="@dimen/doc_title_font_size" /> <TextView android:id="@+id/tvClaimWorkName" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:layout_toRightOf="@+id/tvWorkItemNumber" android:textSize="@dimen/doc_title_font_size" android:text="test type 1"/> <TextView android:id="@+id/tvClaimPlan" android:layout_width="70dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:gravity="center" android:layout_marginRight="2dp" android:layout_marginTop="10dp" android:layout_toRightOf="@+id/tvClaimWorkName" android:textSize="@dimen/doc_title_font_size" android:text="2"/> <EditText android:id="@+id/etClaimFact" android:layout_width="200dp" android:layout_height="wrap_content" android:inputType="number" android:layout_marginLeft="2dp" android:layout_marginRight="1dp" android:layout_marginTop="10dp" android:gravity="center" android:layout_toRightOf="@+id/tvClaimPlan" android:textSize="@dimen/doc_title_font_size" /> </RelativeLayout> 

Screenshot, I type "1234567", and get "7654321":

enter image description here

TextWatcher Code:

  etComment = (EditText) view.findViewById(R.id.etComment); etComment.setText(docWorkComment); etComment.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { SQLiteDatabase db = DBH.getInstance(getActivity().getApplicationContext()).getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(DBH.DocK.DC.NOTE, String.valueOf(s)); db.update(DBH.DocK.TABLE_NAME, cv, "tabID=" + 1 + " and file_id=" + "'" + docId + "'", null); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); 
  • Can you show a screenshot? - Vladyslav Matviienko
  • android:textDirection="anyRtl" try experimenting with this - Silento
  • @metalurgus Added a screenshot - Lucky_girl
  • @Asgard added, but did not help - Lucky_girl
  • @Lucky_girl, maybe in the styles of something? Or is this InstantRun again buggy ... - Yuriy SPb

1 answer 1

You rigidly set the width android:layout_width="200dp" and your EditText went off the screen to the right. In this case, you have exposed android:gravity="center" , i.e. The text is typed in the center, so this effect is obtained.

Remove android:gravity="center" or deal with the size of the width.

  • I put the gravity left, and the effect is the same. - Lucky_girl
  • Removed gravity completely, but the text is typed in the same way. - Lucky_girl
  • @Lucky_girl Remove gravity and try, for example, set android:layout_width="50dp" . See what happens. I think the problem is with the layout of components in width. - mit