I'e been experiencing some odd behavior from the text cursor in the EditText
s of my android application. Essentially, the cursor does not always accurately represent it's position in a word (it's all over the place). As such, typing a character into an edit text can result in the character being placed somewhere different (usually before or after the cursor indicated position). Also, when the cursor is placed inside of or next to a word, that word is often offset slightly.
Here is an example of the phenomenon;
Notice the words moving position from picture to picture, and in the second example the cursor indicates that it is before the i
but is in fact before the e
two indexes to the right.
Here is the EditText
element of this View
in the XML;
<EditText
android:id="@+id/hazard_obs_text"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="@+id/hazard_observation"
android:layout_alignLeft="@+id/hazard_observation"
android:layout_alignRight="@+id/hazard_observation"
android:layout_above="@+id/finalise_hazard"
android:layout_marginTop="5dp"
android:background="@drawable/whitebackselector"
android:hint="Recommendation Text"
android:textSize="9sp"
android:gravity="start"
android:paddingLeft="5dp"
android:enabled="false"
/>
As you can see, it is inside a RelativeLayout
, and has a custom blank white background with some subtle shading around the edge. It is also part of a Fragment
layout. Nothing out of the ordinary as far as I can see. No exceptions or errors are being thrown. I am stumped. Does anyone have any ideas what could be causing this odd behavior?
Extra details by request;
The Layout isn't changed programmatically in any way except to be inflated initially (it is in a Fragment after all). Below is any line of code that interacts programmatically with the above example EditText
-
obsText = (EditText) fragmentView.findViewById(R.id.hazard_obs_text);
...
obsText.setEnabled(tf); // Where tf is a boolean value.
...
obsText.getText().clear();
...
obsText.setText(observations[0].split(" ", 3)[1]); // Where observations[0] is a string.
...
obsText.setText(currentAssessment.obsDescript); // Setting another string.
Below is the full fragment layout. It is worth noting that I am also having the same issue in a very simple LinearLayout -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#070054"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<AutoCompleteTextView
android:id="@+id/hazard_code"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/hazard_code_browse_button"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:hint="Hazard Code"
android:background="@drawable/whitebackselector"
android:singleLine="true"
android:textSize="12sp"
android:selectAllOnFocus="true"
android:paddingLeft="5dp"
android:dropDownWidth="fill_parent"
android:dropDownHeight="125dp"
android:dropDownVerticalOffset="1dp"
android:completionThreshold="1"
/>
<Button
android:id="@+id/hazard_code_browse_button"
android:layout_width="30dp"
android:layout_height="20dp"
android:layout_toLeftOf="@+id/sfrp_drops"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="7dp"
android:background="@drawable/crossselector"
/>
<Spinner
android:id="@+id/hazard_observation"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/sfrp_drops"
android:layout_toLeftOf="@+id/pictures"
android:background="@drawable/whitebackselector"
android:paddingLeft="5dp"
android:dropDownWidth="wrap_content"
android:dropDownHeight="125dp"
android:dropDownVerticalOffset="1dp"
android:enabled="false"
/>
<LinearLayout
android:id="@+id/sfrp_drops"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:layout_width="160dp"
android:layout_height="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
>
<Spinner
android:id="@+id/hazard_severity"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_weight="1"
android:background="@drawable/whitebackselector"
android:prompt="@string/hazard_severity"
android:paddingLeft="5dp"
android:enabled="false"
/>
<Spinner
android:id="@+id/hazard_frequency"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="@drawable/whitebackselector"
android:prompt="@string/hazard_frequency"
android:paddingLeft="5dp"
android:enabled="false"
/>
<Spinner
android:id="@+id/hazard_risk"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/whitebackselector"
android:prompt="@string/hazard_risk"
android:paddingLeft="5dp"
android:enabled="false"
/>
<Spinner
android:id="@+id/hazard_priority"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="@drawable/whitebackselector"
android:prompt="@string/hazard_priority"
android:paddingLeft="5dp"
android:enabled="false"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/pictures"
android:orientation="vertical"
android:layout_width="25dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:background="@drawable/photoreel"
>
<ImageView
android:id="@+id/photo_icon"
android:src="@drawable/hal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
<EditText
android:id="@+id/hazard_obs_text"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="@+id/hazard_observation"
android:layout_alignLeft="@+id/hazard_observation"
android:layout_alignRight="@+id/hazard_observation"
android:layout_above="@+id/finalise_hazard"
android:layout_marginTop="5dp"
android:background="@drawable/whitebackselector"
android:hint="Recommendation Text"
android:textSize="9sp"
android:gravity="start"
android:paddingLeft="5dp"
android:enabled="false"
/>
<EditText
android:id="@+id/hazard_act_text"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="@+id/sfrp_drops"
android:layout_alignLeft="@+id/sfrp_drops"
android:layout_alignRight="@+id/sfrp_drops"
android:layout_above="@+id/finalise_hazard"
android:layout_marginTop="5dp"
android:background="@drawable/whitebackselector"
android:hint="Observation Text"
android:textSize="9sp"
android:gravity="start"
android:paddingLeft="5dp"
android:enabled="false"
/>
<Button
android:id="@+id/finalise_hazard"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_alignRight="@+id/hazard_obs_text"
android:layout_alignLeft="@+id/hazard_act_text"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@drawable/plainbuttonselector"
android:padding="0dp"
android:textColor="#FFFFFF"
android:text="Finalise Entry"
android:enabled="false"
/>
<EditText
android:id="@+id/peoples_at_risk"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_below="@+id/hazard_location"
android:layout_alignLeft="@+id/hazard_code"
android:layout_toLeftOf="@+id/hazard_act_text"
android:layout_marginTop="5dp"
android:layout_marginRight="7dp"
android:background="@drawable/whitebackselector"
android:textSize="9sp"
android:singleLine="true"
android:paddingLeft="5dp"
android:hint="Peoples at Risk"
android:enabled="false"
/>
<EditText
android:id="@+id/hazard_location"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_below="@+id/hazard_code"
android:layout_alignLeft="@+id/hazard_code"
android:layout_toLeftOf="@+id/hazard_act_text"
android:layout_marginTop="5dp"
android:layout_marginRight="7dp"
android:background="@drawable/whitebackselector"
android:textSize="9sp"
android:paddingLeft="5dp"
android:gravity="start"
android:hint="Hazard Location"
android:enabled="false"
/>
<EditText
android:id="@+id/relevant_legistlation"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="@+id/peoples_at_risk"
android:layout_alignLeft="@+id/hazard_code"
android:layout_toLeftOf="@+id/hazard_act_text"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="7dp"
android:background="@drawable/whitebackselector"
android:textSize="9sp"
android:paddingLeft="5dp"
android:gravity="start"
android:hint="Relevant Legislation"
android:enabled="false"
/>
</RelativeLayout>
I am experiencing the issue on a Nexus 10, Galaxy Note 10.1, & Xperia Z2 tablets with the latest version of Android installed. I've also tested this on an old Xperia phone as well which is not having the issue, which begs the question of whether it could be related to screen size. Other applications on the same devices aren't having this issue.
Any help would be greatly appreciated. This has been hounding me for some time now. I am willing to manually award a bounty to anyone who can help towards a solution/explanation.