Gaurav Arora
Gaurav Arora

Reputation: 17264

ListView inside another ListView

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

Upvotes: 6

Views: 4407

Answers (4)

shassss
shassss

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

Haresh Chaudhary
Haresh Chaudhary

Reputation: 4400

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);

Upvotes: 3

Dhruvil Patel
Dhruvil Patel

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

dineth
dineth

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)

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

Upvotes: 1

Related Questions