Sunday 15 September 2013

android - 3 vertical listViews in one scrollview -



android - 3 vertical listViews in one scrollview -

i need implement such screen :

so, i've created adapter imageview, 2 textviews , checkbox.

i need implement 3 listviews , create screen scrollable.

i tried implemen solution, not workable me - made :

<scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:fillviewport="true" android:orientation = "vertical" android:layout_height="match_parent"> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" android:weightsum="1.0" > <linearlayout android:layout_weight="0.5" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"> <textview android:text="@string/textview_settings_categories" style="@style/settings_label"/> <listview android:id="@+id/listview1" android:layout_height="fill_parent" android:layout_width="fill_parent"> </listview> </linearlayout> <linearlayout android:layout_weight="0.25" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"> <textview android:text="@string/textview_settings_categories" style="@style/settings_label"/> <listview android:id="@+id/listview2" android:layout_height="fill_parent" android:layout_width="fill_parent"> </listview> </linearlayout> <linearlayout android:layout_weight="0.25" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"> <textview android:text="@string/textview_settings_categories" style="@style/settings_label"/> <listview android:id="@+id/listview3" android:layout_height="fill_parent" android:layout_width="fill_parent"> </listview> </linearlayout> </linearlayout> </scrollview>

i tried this 1 solution, both not workable me - scrollview can't scrollable.

i tried implement 3 vertical listfragments 1 above another, listviews scrollable inside, scrollview not - can't see bottom of screen.

it's not best practice, if really want functionality, can disallow touch event of parent scrollview 1 time touch , re allow 1 time leave kid container.

this how have done before, "listscanners" listview:

listscanners.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { v.getparent().requestdisallowintercepttouchevent(true); homecoming false; } });

and part of layout relevant question:

/* theres more before ... */ <scrollview android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbarsize="0dp" > <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <relativelayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margintop="5dp" android:layout_gravity="center" android:gravity="center" android:background="@null" > <textview android:id="@+id/emptylist1" android:layout_width="450dp" android:layout_height="80dp" android:textcolor="#6f6f6f" android:textsize="20sp" android:padding="3dp" android:layout_marginbottom="3dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:text="no scanners have been added..."/> <listview android:id="@+id/listview_scanners" android:layout_width="450dp" android:layout_height="80dp" android:padding="3dp" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:cachecolorhint="#00000000" android:divider="#dedede" android:dividerheight="1px"> </listview> </relativelayout> /* theres more after ... */

correct way: ideally should rather have this, layout looks this:

where of import have in linear layout:

android:isscrollcontainer="true"

isscrollcontainer means linearlayout contains view scrolls, meaning can size within linear layout, however, may contain much more when scroll it. here layout:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#afafaf" android:isscrollcontainer="true"> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:background="#ff63ff9b" android:layout_height="50dp" > <textview android:id="@+id/textview_heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="25sp" android:layout_margintop="5dp" android:layout_marginleft="10dp" android:textcolor="#ffffff" android:text="view first list"/> </linearlayout> <relativelayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="150dp" android:layout_margintop="5dp" android:background="@null" > <listview android:id="@+id/listview1" android:layout_width="fill_parent" android:layout_height="130dp" android:cachecolorhint="#00000000" android:divider="#dedede" android:dividerheight="1px"> </listview> </relativelayout> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:background="#ff63ff9b" android:layout_height="50dp" > <textview android:id="@+id/textview_heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="25sp" android:layout_margintop="5dp" android:layout_marginleft="10dp" android:textcolor="#ffffff" android:text="view sec list"/> </linearlayout> <relativelayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="150dp" android:layout_margintop="5dp" android:background="@null" > <listview android:id="@+id/listview2" android:layout_width="fill_parent" android:layout_height="130dp" android:cachecolorhint="#00000000" android:divider="#dedede" android:dividerheight="1px"> </listview> </relativelayout> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:background="#ff63ff9b" android:layout_height="50dp" > <textview android:id="@+id/textview_heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="25sp" android:layout_margintop="5dp" android:layout_marginleft="10dp" android:textcolor="#ffffff" android:text="view 3rd list"/> </linearlayout> <relativelayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="150dp" android:layout_margintop="5dp" android:background="@null" > <listview android:id="@+id/listview3" android:layout_width="fill_parent" android:layout_height="130dp" android:cachecolorhint="#00000000" android:divider="#dedede" android:dividerheight="1px"> </listview> </relativelayout> </linearlayout>

i made in 5 minutes , layout looking this: (this draft, give idea)

and lastly not least, in code display lists, have this:

public class screen_view_lists extends activity { baseadapter listadapter; listview list1,list2,list3; @override public void oncreate(bundle icicle) { super.oncreate(icicle); setcontentview(r.layout.screen_view_packages); list1 = (listview) findviewbyid(r.id.listview1); list2 = (listview) findviewbyid(r.id.listview2); list2 = (listview) findviewbyid(r.id.listview3); listadapter = new adapter_list_main(this, packages);//this own adapter, utilize own custom 1 well. list1.setadapter(listadapter); //setup list back upwards context menu registerforcontextmenu(list1); //setup list back upwards long click events. list1.setlongclickable(true); //action listener long click on item in list list1.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() { public boolean onitemlongclick(adapterview<?> parent, view v, int position, long id) { //do things here } }); //action listener short click on item in list list1.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { //do things here } }); //and 1 . . . } }

android listview android-listview android-scrollview

No comments:

Post a Comment