【问题标题】:Android Viewholder onclicklistener multiple clickAndroid Viewholder onclicklistener 多次点击
【发布时间】:2014-03-27 02:24:45
【问题描述】:

我在查看器 onclicklistener 上有一个问题。 当我按下图像时,它将启动另一个活动。 如果我多次按下图像,它将启动多个活动。

如何让 onclicklistener 只启动一项活动?

public View getView( final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
          final ViewHolder holder;
        if (convertView == null) {

            convertView = mInflater.inflate(R.layout.epi_list_row, null);
            holder = new ViewHolder();

            holder.date = (TextView) convertView.findViewById(R.id.date);
            holder.month_year = (TextView) convertView.findViewById(R.id.month_year);
            holder.time = (TextView) convertView.findViewById(R.id.time);

            holder.status = (ImageView) convertView.findViewById(R.id.status);
            holder.ecg_view = (ImageView) convertView.findViewById(R.id.ecg_view);
            //holder.ecg_view = (Button) convertView.findViewById(R.id.ecg_view);
            holder.check = (CheckBox) convertView.findViewById(R.id.ecg_checkbox_select);


           convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();

        }


         holder.date.setText(mDate[position].toString().substring(8));
            holder.month_year.setText(mDate[position].toString().substring(0, 7));
            holder.time.setText(mTime[position].toString());


            if(mUpdate[position].toString().equals("1")){
                //holder.status.setText("Sent");
                holder.status.setBackgroundResource(R.drawable.sent_icon);
            }else if(mUpdate[position].toString().equals("0")){
                //holder.status.setText("Pending");
                holder.status.setBackgroundResource(R.drawable.pending_icon);
            }


            holder.ecg_view.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    try {
                        getParsedMyXML(position, mFiles.get(position), true);
                    }catch (Exception e) {
                        // TODO Auto-generated catch block                  
                    }

                    // Launch another activity
                    startDrawing(mData, mDate[position] + " " + mTime[position]);
                }
            });


        return convertView;
    }

【问题讨论】:

  • 您是否在 getParsedMyXML 中进行异步调用?
  • getParsedMyXML 中没有异步调用

标签: android onclicklistener


【解决方案1】:

在您的onClick method 中,试试这个:

   if(firstClick == true) {
     firstClick = false;
     // Launch another activity
     startDrawing(mData, mDate[position] + " " + mTime[position]);
   }

firstClick 声明为初始设置为true 的全局布尔变量。然后,其他活动可以在适当的时候将firstClick 值修改回true

【讨论】:

  • 我试过这个方法不行。当视图持有者图片有多次点击时,它仍然会触发多个“onclick事件”
猜你喜欢
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多