android - DialogFragment + listview = getView called too many times -
i have dialogfragment showing custom layout containing list view:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingtop="20dp"> <view android:id="@+id/first_divider" style="@style/divider"/> <listview android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" style="@style/listview"/> <view android:id="@+id/second_divider" style="@style/divider" /> <textview android:id="@+id/textview_error" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" android:textcolor="@color/red" android:layout_margintop="10dp" android:layout_marginleft="24dp" android:layout_marginright="24dp" android:text="@string/ui_alertdialog_checkable_list_dialog_no_item_selected_error"/> </linearlayout> i inflate layout way in oncreatedialog method:
view contentview = getactivity().getlayoutinflater().inflate(r.layout.ui_alertdialog_checkable_list, null); it working, list view's adapter calling getview many times , calling notifydatasetchanged slow. caused way i'm inflating layout : don't attach parent view, android seems unable compute list view's height, , so, creates lot of views using getview.
if set fixed height, works properly, can't that. setting height match_parent doesn't works either.
any 1 knows how have dialog custom layout , working list view?
it took while found solution : using relativelayout fixed problem! sample xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingtop="20dp"> <view android:id="@+id/first_divider" style="@style/divider"/> <listview android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/first_divider" android:layout_above="@+id/bottom_elements" style="@style/listview"/> <linearlayout android:id="@+id/bottom_elements" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignparentbottom="true" > <view style="@style/divider"/> <textview android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/my_textview_text" /> </linearlayout> </relativelayout>
Comments
Post a Comment