35

ListView各項目のレイアウトを個別の XML ファイルで定義した場所があります。このファイルには、RatingBarEditText.

この にプログラムで 7 ~ 8 個のアイテムを作成しましたListView。それらをスクロールすると、かなりバグがあるようです。ここではいくつかの例を示します。

  1. 最初の行の にフォーカスを設定してからEditText下にスクロールすると、他の行からListViewランダムにフォーカスが移動します。EditTextsフォーカスされたものが消えた次EditTextのものがフォーカスされるようです。おそらくこれは意図的なものですが、ユーザーとしては非常に奇妙に思えます。

  2. にフォーカスを設定しEditText、仮想キーボードを受け取り、何かを入力して、仮想キーボードの [完了] ボタンをクリックするとEditText、仮想キーボードが消えるとすぐに が空になります。

  3. をクリックしEditTextて仮想キーボードを受け取り、文字を入力し始めると、入力するとすぐに文字が消えてしまうことがあります。

  4. をクリックするEditTextと、仮想キーボードが表示されますが、EditTextフォーカスが失われ、EditTextもう一度クリックする必要があります。

  5. を に設定してもRatingBarfocusable="false"スクロール ホイールを動かすと、フォーカスが移動します。

私の問題の 1 つは、仮想キーボードに文字を入力すると、表示されているすべてのリスト項目が再描画されることです (そして、テキストEditTextが空のデータに設定されているため、クリアされます。なぜ Android が文字を入力するたびにリストを再描画することにしました。

これが、それらを描画するために使用している XML です。それらは白い泡で、灰色の境界線があり、いくつかのテキスト、 aRatingBarとa がEditText内側にあります。

<?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>
4

5 に答える 5

19

ListViews は EditTexts をうまく処理できないようです。私はいくつかの調査を行いましたが、コンセンサスは「それをしないでください」のようです。だから私が頼ったのは、LinearLayoutを内部に持つScrollViewである単純なレイアウトファイルを作成することです。onCreate メソッドで、リスト アイテムに使用していたビューを拡張し、それを LinearLayout に追加します。また、View を ArrayList に追加して、後で各 View にデータを保存できるようにします。

これは合理的に聞こえますか?

于 2010-08-12T16:29:04.060 に答える
5

さて、これをマニフェストのアクティビティに追加してください...

android:windowSoftInputMode="adjustPan"

例...

<activity android:name=".mapview.AddParkingLotActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"/>
于 2012-06-29T06:29:36.353 に答える
4

私は同じ問題を抱えていました。キーボードが表示されると、LisView 内の EditText がフォーカスを失っていたので、ListView アイテムから getView を配置しました。

final EditText editInput = (EditText)convertView.findViewById(R.id.edit_input);
editInput.requestFocusFromTouch();

そして、これは私のために働きます。

于 2011-12-08T13:17:14.207 に答える
0

この行にコメントするだけで解決した問題があります

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
于 2014-08-04T07:21:02.030 に答える