I'm triying to load a listview with an AsyncTask, but when the task is complete (onPostExecute method) and set the adapter to the listview the listview's height does not adjust to the items in it.
While the task is in doInBackground method a ProgressBar is shown. After, when the task is complete the ProgressBar is hidden and the ListView is loaded with the AsyncTask results.
My problem is the listview's height which does not show all the items in it.
Here is my code:
The listview declaration:
<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>
the item list template:
<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" />
the onPostExecute method:
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();
}
}
Can you help me please?, i tried all the listview's xml attributes but it seems nothing works.
Thanks in advance.