问题描述
我有一个的ListView
,我已经定义每个项目的布局在一个单独的XML文件。在这个文件我已经包含了的RatingBar
和的EditText
。
我在编程这个的ListView
创建7-8项。当我通过他们的滚动,这似乎是相当马车。下面是一些例子:
-
如果我将焦点设置到
的EditText
排在第一位,然后向下滚动的ListView
,随机EditTexts
从其他行会有重点。这似乎是下一个的EditText
-
如果我将专注于
的EditText
,收到一个虚拟键盘,输入一些东西,然后点击我的虚拟键盘上的完成按钮,在的EditText
作为虚拟键盘消失会尽快清空。 -
有时候,当我点击了
的EditText
,获得虚拟键盘并开始键入字母,这些字母将作为我键入他们很快就消失了。 -
当我点击了
的EditText
,虚拟键盘显示本身,而是的EditText
失去焦点我必须点击的EditText
了。 -
尽管我已经设置了
的RatingBar
到可聚焦=假
,如果我动我的滚轮,它仍然抓住重点。
我的一个问题是所有可见的列表项获得重绘当我输入的虚拟键盘的字符(和自文的的EditText
设置为一些数据,里面是空的,它就会被清除。我不明白为什么机器人将决定我每次输入一个字符重绘列表中。
下面是我用绘制它们的XML。他们是白色的泡沫,有一个灰色的边界,和一些文字,一个的RatingBar
和的EditText
里面的:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:paddingTop =10dip
机器人:paddingBottom会=10dip
机器人:以下属性来=15dip
机器人:paddingRight =15dip
>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=2DIP
机器人:背景=@可绘制/ shape_outer>
<的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=2DIP
机器人:背景=@可绘制/ shape_inner>
<的TextView
机器人:ID =@ + ID / rating_category
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=@色/ dark_gray
机器人:TEXTSTYLE =黑体
机器人:layout_marginBottom =10dip/>
<的RatingBar
机器人:ID =@ + ID / rating_rating
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:numStars =5
机器人:等级=0
机器人:stepSize的=1
机器人:可聚焦=假
机器人:可点击=假
/>
<的EditText
机器人:ID =@ + ID / rating_text
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_column =1
机器人:填充=6dip
机器人:文字颜色=#000000
机器人:重力=左|顶
机器人:行=3
机器人:提示=注释
机器人:imeOptions =actionDone/>
< / LinearLayout中>
< / LinearLayout中>
< / LinearLayout中>
这听起来像列表视图不能处理EditTexts好。我做了一些研究和共识似乎是不这样做。所以,我所诉诸的创建是一个LinearLayout中内的滚动型的简单布局文件。在我的onCreate方法,我吹我用的是查看我的列表项,并把它添加到的LinearLayout。我还加入了查看到ArrayList这样我就可以将数据保存在每个视图以后。
这听起来合理吗?
I have a ListView
where I've defined the layout of each item in a separate XML file. In this file I've included a RatingBar
and an EditText
.
I've programmatically created 7-8 items in this ListView
. When I scroll through them, it seems to be quite buggy. Here are some examples:
If I set focus to the
EditText
in the first row and then scroll down theListView
, randomEditTexts
from other rows will have focus. It seems to be that the nextEditText
after the focused one disappears receives focus. Perhaps this is intentional, but, as a user, it seems very weird.If I set focus to an
EditText
, receive a virtual keyboard, type something, and click the "Done" button on my virtual keyboard, theEditText
will empty as soon as the virtual keyboard disappears.Sometimes, when I click an
EditText
, receive a virtual keyboard and start typing letters, the letters will disappear as soon as I type them.When I click on an
EditText
, the virtual keyboard shows itself, but theEditText
loses focus and I have to click theEditText
again.Even though I've set the
RatingBar
tofocusable="false"
, if I move my scrollwheel, it still grabs focus.
One of my problems is all the visible list items get redrawn when I type a character in the virtual keyboard (and since the text of the EditText
is set to some data, which is empty, it gets cleared. I don't understand why Android would decide to redraw the list every time I type a character.
Here is the XML I'm using to draw them. They are white bubbles, with a gray boarder, and some text, a RatingBar
and an EditText
inside:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:paddingLeft="15dip"
android:paddingRight="15dip"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:background="@drawable/shape_outer">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:background="@drawable/shape_inner">
<TextView
android:id="@+id/rating_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/dark_gray"
android:textStyle="bold"
android:layout_marginBottom="10dip" />
<RatingBar
android:id="@+id/rating_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="0"
android:stepSize="1"
android:focusable="false"
android:clickable="false"
/>
<EditText
android:id="@+id/rating_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:padding="6dip"
android:textColor="#000000"
android:gravity="left|top"
android:lines="3"
android:hint="Comment"
android:imeOptions="actionDone" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
It sounds like ListViews aren't able to handle EditTexts well. I've done some research and the consensus seems to be "don't do that." So what I've resorted to is creating a simple layout file which is a ScrollView with a LinearLayout inside. In my onCreate method, I inflate the View I was using for my list item and add it to the LinearLayout. I'm also adding the View to an ArrayList so I can save the data in each View later on.
Does this sound reasonable?
这篇关于越野车的ListView让我伤心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!