6

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 !

CUSTOM UI

Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44
  • Scrollviews can't be nested. [See more here][1]. [1]: http://stackoverflow.com/questions/4490821/scrollview-inside-scrollview – Snicolas Jul 30 '12 at 12:28

4 Answers4

3

To Achieve this this, You have to do the following::

  1. Create a Vertical ScrollView having Single LinearLayout.
  2. Now Create Horizontal ListViews inside this Linearlayout as shown in the Example below:

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>    

Edit: Adding Dynamically ListView to the LinearLayout.

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);
Haresh Chaudhary
  • 4,390
  • 1
  • 34
  • 57
  • Scrollviews can't be nested...but but but...you can take a Single parent LinearLayout and inside it,you can keep multiple ListViews.Hence the ScrollView will have a single child Linearlayout. – Haresh Chaudhary Jul 30 '12 at 12:31
  • But in this case, I don't know the number of either listViews that I need to make since they are random. How will I achieve that ? – Gaurav Arora Jul 30 '12 at 13:14
  • I have same requirement so will you please provide me sample code I will be thankful to you. Plz – Faiz Anwar Feb 09 '14 at 11:43
1

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)

Check this answer too - https://stackoverflow.com/questions/5398449/how-can-i-create-a-pulse-like-ui-for-an-android-application

Community
  • 1
  • 1
dineth
  • 9,822
  • 6
  • 32
  • 39
0
 <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>
shassss
  • 321
  • 1
  • 13
0

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;
            }
        });
Dhruvil Patel
  • 2,910
  • 2
  • 22
  • 39