简体   繁体   中英

Android programming - Multiline EditText inside ListView

I have a ListView, in which each row contains a TextView and an EditText. I find that I can't get multiline with this EditText. Whatever I type in it, the string doesn't wrap to next line. Besides, the soft keyboard doesn't show "Enter key" -- instead, it shows a "Done" key.

If I copy the block to outside ListView, it works as multiline. But it doesn't work inside ListView.

I'll appreciate it if anyone can shed some light. Thank you!

My ListView row has this layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView 
    android:layout_width="140dp"
    android:layout_height="fill_parent"
    android:gravity="center_vertical|right"
    android:paddingLeft="3dp"
    android:paddingRight="5dp" 
    android:id="@+id/listitem_maindesc"
    android:textColor="#000000"
    android:textSize="16sp"></TextView>

<EditText
    android:id="@+id/listitem_entry"        
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:singleLine="false"
    android:lines="3"
    android:minLines="3"
    android:inputType="textMultiLine"       
    />

</LinearLayout>

I solved a problem equal to this, but changing my OnKeyListener to return false.

I think problem is with your xml because you have not defined in xml that editText should not go above textView so it will take maximum length.

try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"                                 
  android:layout_width="fill_parent"  
  android:layout_height="wrap_content" >
    <TextView 
      android:layout_width="140dp"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:paddingLeft="3dp"
      android:paddingRight="5dp" 
      android:id="@+id/listitem_maindesc"
      android:textColor="#000000"
      android:layout_centerVertical="true"
      android:textSize="16sp" >  </TextView>

    <EditText
      android:id="@+id/listitem_entry"        
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="16sp"
      android:singleLine="false"
      android:layout_alignParentLeft="true"
      android:layout_toLeftOf=""
      android:layout_centerVertical="true"
      android:inputType="textMultiLine"       />
</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM