4

I'm working on an extension of BaseExpandableListAdapter, and have the following implementation of getChildView():

public View getChildView(int groupPosition, int childPosition, 
    boolean isLastChild, View convertView, ViewGroup parent) 
{
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams
        (ViewGroup.LayoutParams.FILL_PARENT, 48);
    RelativeLayout layout = new RelativeLayout(myExpandableListActivity.this);
    layout.setLayoutParams(lp);
    TextView name = new TextView(myExpandableListActivity.this);
    name.setText("testing...");
    layout.addView(name);
    return layout;
}

This code is working, and when I run the application, expand a group and click on a child, the parent application is able to detect onChildClick() correctly.

However, I notice that the onChildClick() does not work anymore if I don't call the setLayoutParms(). My question is, what is happening when I assign AbsListView.LayoutParams to the child view being returned? Why is this required to have my onChildClick() respond in the parent application?

Thanks in advance!

Francisco Alvarado
  • 2,815
  • 2
  • 26
  • 51
superdikery
  • 78
  • 1
  • 6

1 Answers1

0

After playing with other parts of the code some more, it looks like leaving out setLayoutParms() was not what was causing my onChildClick() to not work. I was also using a layout inflater to set up my RelativeLayout, which included a CheckBox. Turns out it was the CheckBox that was causing the child to be unclickable, something that I'll have to look into further.

RelativeLayout spellLayout = (RelativeLayout) 
    getLayoutInflater().inflate(R.layout.testLayout, null);

Thanks for reading!

superdikery
  • 78
  • 1
  • 6
  • Ah, looks like the CheckBox question is already answered elsewhere: http://stackoverflow.com/questions/1683514/android-checkbox-blocks-expandablelistview-ongroupclicklistener – superdikery May 09 '11 at 04:53