android - How to set the Dynamic height to list view in fragment activity..? -


i need implement list view inside scroll view. knw it's not idea using listview inside scroll view it's requirenment of app need implement it. in app im using tablayout 3 type of tabs categories 1,categories 2 , again categories 3 filter data.

in first tab categories 1 need add 2 list view 1 fix items , second dynamic. fist list view fixed can give fixed height it. second list view dynamic need give height according total number of values in list view.

im try many ways give dynamic height not getting task done.

here method alredy try :-

-------------------first ------------------------------- first question

android: how measure total height of listview

public static void gettotalheightoflistview(listview listview) {      listadapter madapter = listview.getadapter();      int totalheight = 0;      (int = 0; < madapter.getcount(); i++) {         view mview = madapter.getview(i, null, listview);          mview.measure(                 view.measurespec.makemeasurespec(0, view.measurespec.unspecified),                  view.measurespec.makemeasurespec(0, view.measurespec.unspecified));          totalheight += mview.getmeasuredheight();         log.w("height" + i, string.valueof(totalheight));      }      viewgroup.layoutparams params = listview.getlayoutparams();     params.height = totalheight             + (listview.getdividerheight() * (madapter.getcount() - 1));     listview.setlayoutparams(params);     listview.requestlayout();  } 

-------------------second------------------------------- question https://stackoverflow.com/questions/17693578

public static class listutils {     public static void setdynamicheight(listview mlistview) {         listadapter mlistadapter = mlistview.getadapter();         if (mlistadapter == null) {             // when adapter null             return;         }         int height = 0;         int desiredwidth = measurespec.makemeasurespec(mlistview.getwidth(), measurespec.unspecified);         (int = 0; < mlistadapter.getcount(); i++) {             view listitem = mlistadapter.getview(i, null, mlistview);             listitem.measure(desiredwidth, measurespec.unspecified);             height += listitem.getmeasuredheight();         }         viewgroup.layoutparams params = mlistview.getlayoutparams();         params.height = height + (mlistview.getdividerheight() * (mlistadapter.getcount() - 1));         mlistview.setlayoutparams(params);         mlistview.requestlayout();     } } 

-------------------error-------------------

in activity xml file, can use linearlayout inside scrollview , can assign android:weight attribute them.

you can assign weight single element , other element ajust @ own available space.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -