Android Listview with Listview item -


i trying create listview each item contains textitem , listview (dynamic length) reason 1 item shown in inner listview. not possible or doing wrong?

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"> <listview xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/outerlistid"     android:layout_width="wrap_content"     android:layout_height="wrap_content" /> </linearlayout> 

inner list item:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">     <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="profile name"         android:id="@+id/nameid"/>     <listview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/innerlistid"/> </relativelayout> 

code:

public class listallactivity extends activity {      protected class mylistitem {         public string name;         public list<string> items;          public mylistitem(string name) {             this.name = name;             this.items = items();         }          public list<string> items() {             arraylist<string> strings = new arraylist<string>();             strings.add("item1");             strings.add("item2");             return strings;         }     }      public class customlistviewadapter extends arrayadapter<mylistitem> {         context context;          public customlistviewadapter(context context, int resourceid, list<mylistitem> items) {             super(context, resourceid, items);             this.context = context;         }          private class viewholder {             textview nametext;             listview mylist;         }          public view getview(int position, view convertview, viewgroup parent) {             viewholder holder = null;             mylistitem rowitem = getitem(position);              layoutinflater minflater = (layoutinflater) context.getsystemservice(activity.layout_inflater_service);             if (convertview == null) {                 convertview = minflater.inflate(r.layout.profile_exercises_list_item, null);                 holder = new viewholder();                 convertview.settag(holder);             } else {                 holder = (viewholder) convertview.gettag();             }             holder.nametext = (textview) convertview.findviewbyid(r.id.profilenamelistitemid);             holder.mylist = (listview) convertview.findviewbyid(r.id.innerlistid);             list<string> items = rowitem.items();             holder.nametext.settext(rowitem.name);             arrayadapter<string> myarrayadapter = new arrayadapter<string>(convertview.getcontext(), android.r.layout.simple_list_item_1, items);             holder.mylist.setadapter(myarrayadapter);             holder.mylist.settextfilterenabled(true);              return convertview;         }     }      public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.mylayout);          listview listview = (listview) findviewbyid(r.id.outerlistid);          arraylist<mylistitem> allitems = new arraylist<mylistitem>();         allitems.add(new mylistitem("name1"));         allitems.add(new mylistitem("name2"));          customlistviewadapter = new customlistviewadapter(this, android.r.layout.simple_list_item_1, allitems);         listview.setadapter(all);         listview.settextfilterenabled(true);     } } 

instead of using nested listviews, can use expandable listview. here useful links playing expandable listview.
http://www.dreamincode.net/forums/topic/270612-how-to-get-started-with-expandablelistview/
http://android-adda.blogspot.com/2011/06/custom-expandable-listview.html


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -