Expandable View to Show fields

78 views Asked by At

I want to create an expandable list view except in this case, when a list item is clicked, i do not want to just want to show another a list of strings but rather I want it to show a layout with text fields and drop downs etc.

So far, I have parentlayout with textview to show the titles, childlayout with fields in it. Just not sure how to show the child layout on list item click. Any help is greatly appreciated!

HashMap<String, List<String>> would be used if I wanted to show a list of strings so in my case, what do I use? HashMap<String, ?> what goes here?

enter image description here

2

There are 2 answers

0
Thomas Riddler On

What I ended up doing, which was much easier and more effective is I created a linear layout with all the fields I needed and added some textviews to serve as section titles. Then I declared it like so

in onCreate

textview= (LinearLayout)findViewById(R.id.textviewid);
textview.setVisibility(View.GONE);

Then wrote a method called toggle

 public void toggle_basicInfo(View v){

            if(textview.isShown()){
                textview.setVisibility(View.GONE);
            }
            else {
                textview.setVisibility(View.VISIBLE);
            }
        }

my xml looked like

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Basic Info"
            android:clickable="true"
            android:onClick="toggle_basicInfo"
            android:textSize="20sp"
            android:paddingTop="8dp"
            android:id="@+id/text"
            android:layout_above="@+id/linearLayout"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:textColor="#ff3a65ff" />

when I click my textview, it will hide/show whatever you define to hide. for example you can hide a LinearLayout etc. Also by doing it this way, state entries for text fields are maintained when hidden and shown.

1
rabz100 On

Looks like you are looking for something like BaseExpandableListAdapter. You can customize both the group and child views with whatever you want.You just have to implement some of the methods.For example getGroupView and getChildView will return any View. You can inflate the view in this method and set it up too.

Here are two articles for reference: http://www.javacodegeeks.com/2013/06/android-expandablelistview-with-custom-adapter-baseexpandablelistadapter.html

http://theopentutorials.com/tutorials/android/listview/android-expandable-list-view-example/