开发者

Android programming - Multiline EditText inside ListView

开发者 https://www.devze.com 2023-03-16 17:32 出处:网络
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,

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/li开发者_Python百科stitem_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>
0

精彩评论

暂无评论...
验证码 换一张
取 消