android - Listview in ScrollView not displaying all items -


i have layout has 2 listviews , inside scrollview because contents can exceed device's height. here layout:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.galleri5.android.activities.imageactivity">      <android.support.v7.widget.toolbar         android:id="@+id/toolbar"         android:elevation="4dp"         android:layout_width="match_parent"         android:layout_height="?attr/actionbarsize"         android:background="#fac80a">          <relativelayout             android:id="@+id/relativelayout"             android:layout_width="match_parent"             android:layout_height="wrap_content">              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="image"                 android:textcolor="#000000"                 android:textsize="17sp"                 android:layout_centervertical="true"                 android:id="@+id/textview80" />              <imageview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/imageview134"                 android:src="@drawable/gallery_page_ic_notifications"                 android:layout_alignparentend="true"                 android:layout_marginright="30dp"                 android:layout_centervertical="true" />          </relativelayout>      </android.support.v7.widget.toolbar>      <scrollview         android:id="@+id/scrollview2"         android:layout_below="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:fillviewport="true">          <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="@drawable/user_profile_bg"             android:orientation="vertical">              <imageview                 android:id="@+id/imageview102"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_gravity="center_horizontal"                 android:layout_marginbottom="25dp"                 android:layout_margintop="10dp"                 android:adjustviewbounds="true" />              <imageview                 android:id="@+id/imageview103"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center_horizontal"                 android:layout_marginbottom="25dp"                 android:src="@drawable/user_profile_activity_1_shape_thin_line_separator" />              <textview                 android:id="@+id/textview38"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginbottom="10dp"                 android:layout_marginleft="30dp"                 android:layout_marginright="30dp"                 android:alpha="0.8"                 android:inputtype="textmultiline"                 android:textcolor="#ffffff" />              <textview                 android:id="@+id/textview39"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginbottom="25dp"                 android:layout_marginleft="30dp"                 android:textappearance="?android:attr/textappearancesmall"                 android:textcolor="#707070" />              <imageview                 android:id="@+id/imageview104"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center_horizontal"                 android:layout_marginbottom="25dp"                 android:src="@drawable/user_profile_activity_1_shape_thin_line_separator" />              <linearlayout                 android:id="@+id/linearlayout3"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_marginbottom="20dp"                 android:layout_marginleft="30dp"                 android:layout_marginright="30dp"                 android:orientation="horizontal">                  <relativelayout                     android:layout_width="match_parent"                     android:layout_height="match_parent">                      <imageview                         android:id="@+id/imageview107"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_centervertical="true"                         android:paddingright="5dp" />                      <linearlayout                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_centervertical="true"                         android:layout_torightof="@+id/imageview107"                         android:orientation="vertical"                         android:paddingleft="5dp">                          <textview                             android:id="@+id/textview45"                             android:layout_width="wrap_content"                             android:layout_height="wrap_content"                             android:alpha="0.8"                             android:paddingbottom="2dp"                             android:textcolor="#ffffff" />                          <textview                             android:id="@+id/textview46"                             android:layout_width="wrap_content"                             android:layout_height="wrap_content"                             android:paddingtop="2dp"                             android:textappearance="?android:attr/textappearancesmall"                             android:textcolor="#707070"                             android:textsize="12sp" />                     </linearlayout>                      <imageview                         android:id="@+id/imageview108"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignparentend="true"                         android:layout_centervertical="true"                         android:src="@drawable/image_page_button_bookmark" />                 </relativelayout>             </linearlayout>              <imageview                 android:id="@+id/imageview109"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center_horizontal"                 android:layout_marginbottom="10dp"                 android:src="@drawable/user_profile_activity_1_shape_thin_line_separator" />              <android.support.v7.widget.cardview                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_marginbottom="35dp"                 android:layout_marginleft="30dp"                 android:layout_marginright="30dp">                  <linearlayout                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:background="#343031"                     android:orientation="vertical">                      <textview                         android:id="@+id/textview47"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginleft="25dp"                         android:layout_margintop="15dp"                         android:text="this image part of..."                         android:textcolor="#707070" />                      <imageview                         android:id="@+id/imageview110"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_gravity="center_horizontal"                         android:layout_marginbottom="20dp"                         android:layout_margintop="10dp"                         android:src="@drawable/user_profile_activity_1_shape_thin_line_separator" />                      <listview                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:id="@+id/listview2" />                      <textview                         android:id="@+id/textview57"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginbottom="20dp"                         android:layout_marginleft="30dp"                         android:text="see galleries"                         android:textcolor="#707070" />                  </linearlayout>               </android.support.v7.widget.cardview>              <imageview                 android:id="@+id/imageview125"                 android:layout_width="305dp"                 android:layout_height="wrap_content"                 android:layout_gravity="right"                 android:layout_marginbottom="20dp"                 android:src="@drawable/image_page_belongs_to_shape_line_separator_1" />              <listview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:id="@+id/listview6" />              <edittext                 android:id="@+id/edittext6"                 android:layout_width="300dp"                 android:layout_height="wrap_content"                 android:layout_marginleft="40dp"                 android:alpha="0.8"                 android:inputtype="text"                 android:eleganttextheight="true"                 android:enabled="true"                 android:hint="comment"                 android:textcursordrawable="@null"                 android:textcolor="#ffffff"                 android:textcolorhint="#ffffff"                 android:layout_margintop="10dp"                 android:backgroundtint="#fac80a" />          </linearlayout>     </scrollview>  </relativelayout> 

the 2 listviews have id listview2 , listview6. have set adapters both listview properly. getting data backend. both listviews, getting 2 items backend showing 1 item in each listview. trying add item second listview, using notifydatasetchanged() not working too. getting 1 item. possible reason , how fix it?

here did, in case else having similar problem:

note: solution inefficient. using because have @ max 2 items in listview. not recommend others if have listview has significant number of items.

public static void setlistviewheightbasedonchildren(listview listview) {               listadapter listadapter = listview.getadapter();             if (listadapter == null) {             // pre-condition                   return;             }              int totalheight = listview.getpaddingtop() + listview.getpaddingbottom();             (int = 0; < listadapter.getcount(); i++) {                  view listitem = listadapter.getview(i, null, listview);                  if (listitem instanceof viewgroup) {                     listitem.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content));                  }                  listitem.measure(0, 0);                  totalheight += listitem.getmeasuredheight();             }              viewgroup.layoutparams params = listview.getlayoutparams();             params.height = totalheight + (listview.getdividerheight() * (listadapter.getcount() - 1));                       listview.setlayoutparams(params);         } 

i called function on both listviews after setting adapter. hope helps.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -