【问题标题】:Button in fragment called in adapter在适配器中调用的片段中的按钮
【发布时间】:2015-12-22 10:33:17
【问题描述】:

我是一个新手 android 开发人员,我有一个包含两个复选框和一个按钮的列表。按钮在列表类中,复选框在适配器类中。当所有复选框都被选中时,我必须进行片段事务,这是按钮出现的时候。有没有办法从适配器中的片段调用按钮? 如果有人能告诉我,我将不胜感激

public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        LayoutInflater mInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.ijueces_list_rondas, null);

            holder = new ViewHolder();
            holder.olblTable = (TextView) convertView.findViewById(R.id.lblTable);
            holder.olblWhite = (TextView) convertView.findViewById(R.id.lblWhite);
            holder.olblBlack = (TextView) convertView.findViewById(R.id.lblBlack);
            holder.ocheckBox1 = (CheckBox) convertView.findViewById(R.id.checkBox1);
            holder.ocheckBox2 = (CheckBox) convertView.findViewById(R.id.checkBox2);
            final CheckBox ocheckBox1 = (CheckBox) convertView.findViewById(R.id.checkBox1);
            final CheckBox ocheckBox2 = (CheckBox) convertView.findViewById(R.id.checkBox2);

            holder.ocheckBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 
            {

                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
                {
                    if(isChecked){
                        counter=0;
                        if(ocheckBox2.isChecked()==true){
                            counter=0;
                        }
                        else{

                        }
                    }
                    else{
                        counter--;
                    }   
                }
            });

            holder.ocheckBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 
            {
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
                {
                    if(isChecked){
                        counter++;
                        if(ocheckBox1.isChecked()==true){

                        }
                    }
                    else{

                    }   
                }
            });

抱歉,我使用的是小型设备,它不允许我编辑代码(那是我的适配器类)

【问题讨论】:

  • 请输入您的代码
  • 点击按钮时你想做什么?
  • 其实我不明白你为什么需要它从适配器调用?您可以从活动中调用它。
  • 您想自动调用它(无需用户交互)吗?
  • 好吧,在检查完列表的所有行之后,按钮调用webservice来更新数据库,所以用户必须点击按钮

标签: android listview checkbox adapter


【解决方案1】:

在您的适配器类中创建一个返回检查项目计数的方法。并从您的活动中调用它,例如

int count = adapter.getCheckedCount();

如果它们都被选中(计数等于您的列表大小),则继续进行 Web 服务调用。

here我做了同样的事情..你可以得到一些想法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2011-10-22
    相关资源
    最近更新 更多