简体   繁体   中英

how to add listview in listview in android?

i adding in listview item as 3 textview and i want to display listview item with 3 text view and listview.I am doing like these...

  <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/seating_people_sno_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:text="Sno"
            android:textColor="#e73e97"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/seating_tname_txt"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:maxLines="2"
            android:text="Table Name"
            android:textColor="#e73e97"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/seating_seats_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:text="Seating"
            android:textColor="#e73e97"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/seating_seated_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:text="Seated"
            android:textColor="#e73e97"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/seating_add_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:text="Add"
            android:textColor="#e73e97"
            android:textSize="20sp"
            android:textStyle="bold" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dip"
        android:layout_marginTop="7dp"
        android:background="#c6c6c6" />

    <ListView
        android:id="@+id/seatingchart_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:divider="#c6c6c6"
        android:dividerHeight="2dp" >

in these xml contain listview for listview i add one more xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/seatingparentlist_sno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:paddingBottom="20dp"
        android:paddingTop="20dp"
        android:textSize="20sp"
        android:textColor="#595959" />

    <TextView
        android:id="@+id/seatingparentlist_tablename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/seatingparentlist_sno"
        android:paddingBottom="20dp"
        android:paddingTop="20dp"
        android:textSize="20sp"
        android:textColor="#595959" />

    <TextView
        android:id="@+id/seatingparentlist_seating"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_toRightOf="@+id/seatingparentlist_tablename"
        android:paddingBottom="20dp"
        android:paddingTop="20dp"
        android:textSize="20sp"
        android:textColor="#595959" />

    <TextView
        android:id="@+id/seatingparentlist_seated"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_toRightOf="@+id/seatingparentlist_seating"
        android:paddingBottom="20dp"
        android:paddingTop="20dp"
        android:textSize="20sp"
        android:textColor="#595959" />

    <ImageView
        android:id="@+id/seatingparentlist_addbtn"
        android:layout_width="40dp"
        android:layout_height="40dp"
         android:paddingTop="20dp"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/seatingparentlist_seated"
/>
</RelativeLayout>
<ScrollView android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
     xmlns:android="http://schemas.android.com/apk/res/android" >
<ListView android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
       android:divider="#c6c6c6"
            android:dividerHeight="2dp"
    android:id="@+id/seatingparentlist_list">
</ListView>
</ScrollView>
</LinearLayout>

        </ListView>
    </LinearLayout>

i am using one more listview in these xml for these list view i am using one more xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:orientation="horizontal">
      <TextView
            android:id="@+id/detailseating_list_peoplename"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:textColor="#595959"
            android:text="sai.."
            android:textSize="20sp"
            android:layout_gravity="center"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/detailseating_list_brideorgroom"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:textColor="#595959"
            android:text="sai.."
            android:textSize="20sp"
            android:layout_gravity="center"
            android:textStyle="bold" /> 

       <ImageView
            android:id="@+id/detailseating_list_rsvp_img"
            android:layout_width="25dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="05dp"
            android:textColor="#595959"
            android:textSize="20sp"
            android:src="@drawable/cancelicon"
            android:layout_gravity="center"
            android:textStyle="bold" /> 
    </LinearLayout>

these must me using in single activity if any have idea please help me

All you need is Expandable ListView

They've also given an example in API demos.

Try to modify Jeff Sharkey's approach of making a sectioned list, to suit your needs.

As you want a list to be in another list, why don't you set the other list's adapter as an adapter element to your main list?

This is how it can be done,

Make a custom adapter that extends BaseAdapter then

 MyListAdapter adapter = new MyListAdapter(Your Context here);  
        adapter.addAdapter(new ArrayAdapter<String>(this,  
            R.layout.list_item, new String[] { "Text1", "Text2" }));  

        ListView mainList = new ListView(Context);  
        list.setAdapter(adapter);  
        this.setContentView(list);  

That should do it...

这是为此创建custome listview的好方法。您可以轻松获取该示例的演示。如果未获取结果,请尝试使用android的api demo。有很多演示,因此

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM