我正在研究 BaseExpandableListAdapter 的扩展,并具有以下 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;
}
此代码有效,当我运行该应用程序时,展开一个组并单击一个子项,父应用程序能够正确检测到 onChildClick()。
但是,我注意到如果我不调用 setLayoutParms(),onChildClick() 将不再起作用。我的问题是,当我将 AbsListView.LayoutParams 分配给返回的 subview 时发生了什么?为什么需要让我的 onChildClick() 在父应用程序中响应?
提前致谢!
最佳答案
在尝试了代码的其他部分之后,似乎遗漏 setLayoutParms() 并不是导致我的 onChildClick() 无法工作的原因。我还使用布局 inflater 来设置我的 RelativeLayout,其中包括一个 CheckBox。原来是 CheckBox 导致了 child 无法点击,我必须进一步调查。
RelativeLayout spellLayout = (RelativeLayout)
getLayoutInflater().inflate(R.layout.testLayout, null);
感谢阅读!
关于android - ExpandableListAdapter.getChildView() 与 AbsListView.LayoutParams 的交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5925893/