【问题标题】:ExpandableListAdapter.getChildView() interaction with AbsListView.LayoutParamsExpandableListAdapter.getChildView() 与 AbsListView.LayoutParams 的交互
【发布时间】:2011-05-08 06:00:20
【问题描述】:

我正在开发 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 分配给要返回的子视图时会发生什么?为什么需要让我的 onChildClick() 在父应用程序中响应?

提前致谢!

【问题讨论】:

    标签: android event-handling parent-child android-listview


    【解决方案1】:

    在更多地使用代码的其他部分之后,看起来省略 setLayoutParms() 并不是导致我的 onChildClick() 无法工作的原因。我还使用布局充气器来设置我的 RelativeLayout,其中包括一个 CheckBox。原来是 CheckBox 导致孩子无法点击,我必须进一步研究。

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

    感谢阅读!

    【讨论】:

    猜你喜欢
    • 2013-09-20
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多