【问题标题】:how to get the checked position of listview and send it to another class如何获取列表视图的选中位置并将其发送到另一个类
【发布时间】:2018-11-26 06:02:55
【问题描述】:

我想获取选中的位置并将其发送到另一个类以使用它这里是代码

selection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                        // TODO Auto-generated method stub
                        if (isChecked) {
                            Toast.makeText(MissionsListAdapter.this.context,
                                    "You checked item" + ipostion, Toast.LENGTH_LONG).show();



                        } else {

                        }
                    }

我将 iposition 发送到另一个班级,我尝试了很多方法,但出现错误

【问题讨论】:

    标签: android xml listview


    【解决方案1】:

    试试这个(创建一个新的 listView 并将其与现有的相关联,然后使用函数 getPositionForView 获取您检查的位置)

    ListView lv = getListView();
    int position = lv.getPositionForView(v);
    

    好运();

    【讨论】:

      【解决方案2】:

      界面可以轻松解决您的问题。

      接口的使用持有你的接口实现类的引用。

      1. 使用方法创建接口。
      2. 在您打算获取位置的类上实现它并重写获取回调的方法。
      3. 将类引用作为参数传递给列表视图。
      4. 需要传递位置时,使用监听器类引用调用接口方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-14
        • 2020-03-28
        • 2021-12-21
        • 1970-01-01
        • 1970-01-01
        • 2018-01-22
        相关资源
        最近更新 更多