Multiple Textviews In Expandablelistview Android
Solution 1:
I'm an idiot. I figured it out. Thank you @Krupal you pointed me in the right direction. If you place anything as an answer i'll select you because you got me thinking the right way.
So what I ended up doing here was I created a custom List Adapter. I won't add the entire class to keep it short. The key was to use set the adapter to only return one child. Then in the child that was returned (XML below) I had all of my needed fields added in. So now when I expanded the list only one child would be visible. Also in my getChildView() I defined all needed entries for the layout for the children. Don't know if this is the perfect way to do it but worked nicely for my needs.
This is where I actually configured the child with my data.
@Overridepublic View getChildView(int groupPosition, finalint childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
finalStringchildText= (String) getChild(groupPosition, 0);
finalStringchildTextSecond= (String) getChild(groupPosition, 1);
finalStringchildTextThird= (String) getChild(groupPosition, 2);
finalStringdeviceName= (String) getChild(groupPosition, 3);
if (convertView == null) {
LayoutInflaterinfalInflater= (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextViewtxtListChild= (TextView) convertView
.findViewById(R.id.lblListItem);
TextViewtxtListChildTwo= (TextView) convertView
.findViewById(R.id.lblListItemTwo);
TextViewtxtListChildThree= (TextView) convertView
.findViewById(R.id.lblListItemThree);
//rest of logic!
}
Setting the children count to 1
@OverridepublicintgetChildrenCount(int groupPosition) {
return1;
}
XML Layout for the child elements
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#000000"><RelativeLayoutandroid:layout_width="340dp"android:layout_height="wrap_content"android:layout_gravity="center_horizontal|right"android:background="#f9fcff"><LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="fill_parent"android:layout_centerHorizontal="true"android:layout_alignParentTop="true"android:background="#4d86ff"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="45dp"android:layout_gravity="center_horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textAppearance="@android:style/TextAppearance.Medium"android:layout_marginLeft="10dp"android:text="Large Text"android:id="@+id/lblListItem"android:textColor="#ffffff"android:layout_alignTop="@+id/textView5"android:layout_toRightOf="@+id/textView5"android:layout_toEndOf="@+id/textView5" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:textAppearance="@android:style/TextAppearance.Medium"android:text="Device ID: "android:id="@+id/textView5"android:layout_centerVertical="true"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"android:textColor="#ffffff" /><Buttonstyle="?android:attr/buttonStyleSmall"android:layout_width="80dp"android:layout_height="wrap_content"android:text="Tags"android:id="@+id/btnTags"android:background="#ffffff"android:singleLine="true"android:layout_alignTop="@+id/lblListItem"android:layout_alignParentRight="true"android:layout_alignParentEnd="true"android:layout_marginRight="15dp"android:layout_marginEnd="15dp" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="45dp"android:layout_gravity="center_horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:textAppearance="@android:style/TextAppearance.Medium"android:text="Status: "android:id="@+id/textView6"android:layout_centerVertical="true"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"android:textColor="#ffffff" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:textAppearance="@android:style/TextAppearance.Medium"android:text="Large Text"android:id="@+id/lblListItemTwo"android:textColor="#ffffff"android:layout_alignTop="@+id/textView6"android:layout_toRightOf="@+id/textView6"android:layout_toEndOf="@+id/textView6" /></RelativeLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center_horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:layout_marginBottom="10dp"android:textColor="#ffffff"android:textAppearance="@android:style/TextAppearance.Medium"android:text="Description: "android:id="@+id/textView7"android:layout_marginStart="15dp"android:layout_alignTop="@+id/lblListItemThree"android:layout_alignParentLeft="true"android:layout_alignParentStart="true" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="20dp"android:layout_marginTop="6dp"android:layout_marginRight="13dp"android:layout_marginBottom="10dp"android:textAppearance="@android:style/TextAppearance.Medium"android:text="Large Text"android:id="@+id/lblListItemThree"android:textColor="#ffffff"android:layout_marginStart="39dp"android:layout_alignParentTop="true"android:layout_toRightOf="@+id/textView7"android:layout_toEndOf="@+id/textView7" /></RelativeLayout></LinearLayout></RelativeLayout>
Post a Comment for "Multiple Textviews In Expandablelistview Android"