同一活动中的两个可扩展列表视图

发布于 2024-11-26 21:15:45 字数 1699 浏览 4 评论 0原文

我在同一个活动(对于 3d 翻转动画)中有两个相对布局,我使用按钮在它们之间旋转。 每个布局都包含一个可扩展的列表视图,该视图有自己的适配器(和自定义布局), 我注意到,一旦创建了可扩展列表视图,第二个 exp.列表视图不会捕获 onclick 事件,而是捕获第一个 exp。显示的列表视图。

我尝试向每个列表视图添加扩展侦听器(OnGroupExpandListener),但尽管我每次都停在正确的断点处,但组本身的扩展并未发生在向用户显示的当前可扩展列表中。

你能帮我一下吗?

谢谢!

添加了我的代码:

firstList = (ExpandableListView)findViewById(R.id.firstList);
firstList.setOnChildClickListener(listItemClick);
firstList.setOnGroupExpandListener(listFirstGroupClick);


private OnGroupExpandListener listFirstGroupClick = new OnGroupExpandListener() {

    @Override
    public void onGroupExpand(int groupPosition) {
        String correlationid =   
                          (String)listViewAdapter.getGroup(groupPosition);
        try {
              secondList =   
                               (ListView)findViewById(R.id.lstSecond);
            listSecondViewAdapter = new 
                                 SecondListAdapter(getBaseContext(), correlationid);
            secondList.setAdapter(listSecondViewAdapter );
                            //You will notice that both have the same listener 
                            // its because they perform the same action
                            // but with a changing parameter
                            secondList.setOnChildClickListener(listItemClick)
        } catch (Exception e) {
            e.printStackTrace();
        }
    } 
};

    private OnChildClickListener listItemClick = new OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        DO SOMETHING...
        return false;
    }
}; 

I have two relative layout in the same activity (for a 3d flip animation) that I rotate between them using a button.
Each layout contains an expandable list view that has its own adapter (and custom layout),
i've noticed that once an expanadable list view is created the second exp. list view does not catch the onclick event but rather the first exp. list view that was displayed.

I've tried adding an expand listener to each of the listviews (OnGroupExpandListener) but although I stopped at the correct breakpoint each time, the expansion of the group itself did not occur in the current expandable list that was shown to the user.

Could you please help me out?

Thanks!

added my code:

firstList = (ExpandableListView)findViewById(R.id.firstList);
firstList.setOnChildClickListener(listItemClick);
firstList.setOnGroupExpandListener(listFirstGroupClick);


private OnGroupExpandListener listFirstGroupClick = new OnGroupExpandListener() {

    @Override
    public void onGroupExpand(int groupPosition) {
        String correlationid =   
                          (String)listViewAdapter.getGroup(groupPosition);
        try {
              secondList =   
                               (ListView)findViewById(R.id.lstSecond);
            listSecondViewAdapter = new 
                                 SecondListAdapter(getBaseContext(), correlationid);
            secondList.setAdapter(listSecondViewAdapter );
                            //You will notice that both have the same listener 
                            // its because they perform the same action
                            // but with a changing parameter
                            secondList.setOnChildClickListener(listItemClick)
        } catch (Exception e) {
            e.printStackTrace();
        }
    } 
};

    private OnChildClickListener listItemClick = new OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        DO SOMETHING...
        return false;
    }
}; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文