Reputation: 17264
I've to make a horizontal list view inside a vertical list view. Both list views can have any number of elements and both needs to be scrollable.
How will I achieve this because I've read that android doesn't support list view hierarchy.
Thanks !
Upvotes: 6
Views: 4407
Reputation: 321
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Accounts" />
<ListView
android:id="@+id/Accounts"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#FF4500" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Contacts" />
<ListView
android:id="@+id/con_listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
</LinearLayout>
Upvotes: 0
Reputation: 4400
To Achieve this this, You have to do the following::
Hence this will let you scroll vertically in the Screen as well as Horizontally in each ListView.
for eg.
<ScrollView>
<LinearLayout..... //this a vertically oriented layout
>
<ListView/>
.
.//This listViews Are Horizontal
.
<ListView>
</Linearlayout>
</ScrollView>
LinearLayout ll=(LinearLayout)findViewById(R.id.id_given_in_the_XML_file);
ListView lv=new ListView(Activityname.this);
.
.
.
Do All ListView Processing Here
.
.
.
lv.setAdapater(adapter);
ll.addView(lv);
Upvotes: 3
Reputation: 2930
It is not possible but you can do one trick that i have used and worked for me too. You can stop(interrupt) outer listview s scroll method by using this :)
Suppose you have listview LV inside Horizontal Listview HV then you have to write following in the touch method of list view-
lv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg1.getAction() == MotionEvent.ACTION_DOWN || arg1.getAction() == MotionEvent.ACTION_MOVE)
{
HV.requestDisallowInterceptTouchEvent(true);
}
return false;
}
});
Upvotes: 0
Reputation: 9942
I would suggest using a ListView to scroll vertically and use a LinearLayout inside a ScrollView to do the horizontal scrolling.
ListView - item 1: - HorizontalScrollView - LinearLayout(orientation:horizontal)
Upvotes: 1