I have a TableLayout
, and a dynamic view is added to the layout. Whenever a layout has an EditText
cursor, it is not displayed on the EditText
, but its cursor is displayed on top of the EditText
, which is equal to the TextView
.
I added an onClick
event, an XML file for EditText
and TextView
and an XML file for the main layout.
My TextView
:
textView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { textView.setSelection(textView.getText().toString().length()); textView.requestFocus(); textView.requestFocusFromTouch(); textView.setCursorVisible(true); return false; } });
XML file:
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:scrollbars="vertical" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="10dp" android:focusable="true" android:focusableInTouchMode="false" android:text="@string/title_form_details" android:textSize="25dp" /> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fieldsContainer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical" android:shrinkColumns="1" android:stretchColumns="1" > </TableLayout> </LinearLayout> </ScrollView>
TextView
XML File:
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|left" android:paddingBottom="0dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="5dp" />
EditText
XML File:
<?xml version="1.0" encoding="utf-8"?> <EditText xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/control" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cursorVisible="true" android:textColor="#000000" android:textCursorDrawable="@null" />
Dynamically add a TextView
, and in the next line I add an EditText
view, but whenever I clicked EditText
, the cursor is displayed on the TextView
.
source share