android - Merging two listviews one above another with a common scroll -


i working on application in have taken account 2 listviews 1 above , common scroll. know not best practice, instead should have taken single listview problem layouts doesn't seem possible sinlge listview. first listview contain list of friend requests can accept or ignore , not static , can vary no limit , second list contain friends may vary i.e not static. if have show these 2 things, should have preferred single listview , can done actual problem arises when have add alphabetical sorting of second list i.e friends list using side bar , applicable second list not first one. 1 screenshot without side bar

enter image description here

but alphabetical side bar there new connections. don't think, can possible single list since alphabetical side bar added whole list not part of list. right trying save myself using scrollview 2 listviews since expensive. need best way how go type of structure. should take 2 listview inside scrollview or can done single listview more preferred.

please pour suggestions. in advance.

what putting 2 listviews 1 after other inside linearlayout container , put container inside scrollview? (programatically) calculate total height listview needs in order wrap it's content, listviews never scroll scrollview will. here idea:

layout

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >     <!-- container -->     <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical" >         <!-- list views -->         <listview             android:id="@+id/listview1"             android:layout_width="match_parent"             android:layout_height="wrap_content" >         </listview>         <listview             android:id="@+id/listview2"             android:layout_width="match_parent"             android:layout_height="wrap_content" >         </listview>     </linearlayout> </scrollview> 

code

private void resizelistview(listview listview) {     listadapter adapter = listview.getadapter();      int count = adapter.getcount();     int itemsheight = 0;     // views have same layout, of them have     // same height     view onechild = listview.getchildat(0);     if( onechild == null)         return;     itemsheight = onechild.getheight();     // resize list view     linearlayout.layoutparams params = (linearlayout.layoutparams)listview.getlayoutparams();     params.height = itemsheight * count;     listview.setlayoutparams(params); } 

you may want (actually need to) wait listview drawn getchildat(int index) can return view , avoid getting null. can achieve adding oncreate:

viewtreeobserver listvto = listview.getviewtreeobserver(); listvto.addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() {     @override     public void ongloballayout() {         listview.getviewtreeobserver().removeongloballayoutlistener(this);         resizelistview(listview);     } }); 

just suggestion, may want try new recyclerview because can handle recycling different types of views


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -