开发者

ExpandableListAdapter.getChildView() interaction with AbsListView.LayoutParams

开发者 https://www.devze.com 2023-03-04 15:07 出处:网络
I\'m working on an extension of BaseExpandableListAdapter, and have the following implementation of getChildView():

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 pare开发者_JAVA百科nt application?

Thanks in advance!


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消