简体   繁体   中英

How to make child in ExpandableListView a textbox instead of a list for Android?

So I have an ExpandableListView. Right now I have 3 Items in The parent List. When I click on one of those, the child list (sublist pops up). What I want is for a textbox to show up underneath rather than a list.

I want a list for the parent, but a textbox for the child. I'm not sure how to do this. This is my code right now:

public void onCreate(Bundle savedInstanceState) {
    try{
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_assignment);

    SimpleExpandableListAdapter expListAdapter =
        new SimpleExpandableListAdapter(
                this,
                createGroupList(),              // Creating group List.
                R.layout.group_row,             // Group item layout XML.
                new String[] { "Group Item" },  // the key of group item.
                new int[] { R.id.row_name },    // ID of each group item.-Data under the key goes into this TextView.
                createChildList(),              // childData describes second-level entries.
                R.layout.child_row,             // Layout for sub-level entries(second level).
                new String[] {"Sub Item"},      // Keys in childData maps to display.
                new int[] { R.id.grp_child}     // Data under the keys above go into these TextViews.
            );
        setListAdapter( expListAdapter );       // setting the adapter in the list.

    }catch(Exception e){
        System.out.println("Errrr +++ " + e.getMessage());
    }
}


//Create Headings of Assignment attributes
private List createGroupList() {
    ArrayList result = new ArrayList();

    //Create string array for Assignment Topic headings
    String[] topics = {"1", "2", "3"};

    //Iterate through array of names to lay them out correctly
    for( int i = 0 ; i < 3 ; ++i ) { 

      HashMap m = new HashMap();
      m.put( "Group Item", topics[i] ); // the key and it's value. 
      result.add( m );
    }
    return (List)result;

}

@SuppressWarnings("unchecked")
private List createChildList() {

    ArrayList result = new ArrayList();
    for( int i = 0 ; i < 3 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
      /* each group need each HashMap-Here for each group we have 3 subgroups */
      ArrayList secList = new ArrayList();
      for( int n = 0 ; n < 3 ; n++ ) {
        HashMap child = new HashMap();
        child.put( "Sub Item", "Sub Item " + n );
        secList.add( child );
      }
     result.add( secList );
    }
    return result;
}

Obviously, I'm creating a childList when I want the child to be a text box. Not sure how to implement this tho. Any help greatly appreciated!

try to place only an edittextview in "R.layout.child_row" . If it gives an error then place a textview also but make it invisible.I hope that will solve the problm

It's very simple, you should create a layout called: child_layout_row like so...

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="match_parent"> 
    <EditText android:id="@+id/text_edit_child"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />
</LinearLayout>

and instead of R.layout.child_row , use R.layout.child_layout_row that's it....

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