0

AsyncTask を使用してリストビューを読み込もうとしていますが、タスクが完了し (onPostExecute メソッド)、アダプターをリストビューに設定すると、リストビューの高さがその項目に合わせて調整されません。

タスクが doInBackground メソッドにある間、ProgressBar が表示されます。その後、タスクが完了すると、ProgressBar が非表示になり、ListView に AsyncTask の結果が読み込まれます。

私の問題は、すべてのアイテムが表示されないリストビューの高さです。

これが私のコードです:

リストビュー宣言:

       <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Comments"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#262023"
                android:textStyle="bold" />

            <ProgressBar
                android:id="@+id/pbComentarios"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />

            <ListView
                android:id="@+id/lvComentarios"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:smoothScrollbar="true" >
            </ListView>

             <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#bbb" />

        </LinearLayout>

アイテム リスト テンプレート:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <ImageButton
        android:id="@+id/ibUser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_my_calendar" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/tvUsername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="5dp"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/tvFechacomentario"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#aaa" />
        </LinearLayout>

        <TextView
            android:id="@+id/tvComentario"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000" />
    </LinearLayout>
</LinearLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#000" />

onPostExecute メソッド:

protected void onPostExecute(ArrayList<Comentario> comentariosList) {
        pbComentarios.setVisibility(View.GONE); // hiding progressbar
        if( comentariosList != null ){
            comentarios = comentariosList;
            icAdapter.setComentarios(comentarios); // setting the arraylist to adapter which extends BaseAdapter
            lvComentarios.setAdapter(icAdapter); // setting adapter to listview
            lvComentarios.setDividerHeight(0);
            lvComentarios.refreshDrawableState(); 
            icAdapter.notifyDataSetChanged();
        }
    }

リストビューのすべての xml 属性を試しましたが、何も機能しないようです。

前もって感謝します。

4

2 に答える 2

1

代わりにこれを試してください:

<ListView
        android:id="@+id/lvComentarios"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:smoothScrollbar="true" >

編集:これを試してください:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Comments"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#262023"
            android:textStyle="bold" />

        <ProgressBar
            android:id="@+id/pbComentarios"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

        <ListView
            android:id="@+id/lvComentarios"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:smoothScrollbar="true" />

         <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#bbb" />

    </LinearLayout>

また、より高いビューの高さが「match_parent」であることを確認してください。そうしListViewないと、必要に応じてスペース全体が占有されません。「match_parent」または「1」の重みで 0 を使用して遊んでください (上記のように)。

于 2013-01-07T02:44:07.493 に答える
0

わかった!!問題は、すべてのレイアウトが ScrollView 内にあり、これにより listview がスクロールしてその高さを取得できなかったため、それを削除したため、すべてが正常に機能するようになりました。どうもありがとうございました。

于 2013-01-08T03:35:23.313 に答える