如何在Android中使用单选复选框

用户名
public class ImageAdapter extends BaseAdapter 
 {
      private LayoutInflater mInflater;
      private Context mContext;
      public ImageAdapter(Context context) 
      {
           mContext = context;
      }
      public int getCount() 
      {
           return count;
      }
      public Object getItem(int position) 
      {
           return position;
      }
      public long getItemId(int position) 
      {
           return position;
      }
      public View getView(final int position, View convertView, ViewGroup parent) 
      {
           ViewHolder holder;
           if (convertView == null) 
           {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(mContext).inflate(R.layout.state_info, null);

                holder.textview = (TextView) convertView.findViewById(R.id.thumbImage);                  

                holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox);                   
                convertView.setTag(holder);

           } 
           else 
           {
                holder = (ViewHolder) convertView.getTag();
           }          
           holder.checkbox.setId(position);
           holder.textview.setId(position);

           holder.checkbox.setOnClickListener(new OnClickListener() {
                public void onClick(View v) 
                {       
                    // String h="hello";
                     CheckBox cb = (CheckBox) v;
                     int id = cb.getId();

                     if(cb.isChecked())
                     {
                         cb.setChecked(false);
                     }                        
                     Toast.makeText(Four.this, "Selected CheckBox ID" + v.getId(), Toast.LENGTH_SHORT).show();

                }
           });

           holder.textview.setText(items.get(position).getName());

           holder.checkbox.setChecked(thumbnailsselection[position]);
           holder.id = position;
           return convertView;
      }          
      public void clear()
      {
          CheckBox cb=(CheckBox)findViewById(R.id.itemCheckBox);
        //  int id=cb.getId();
          for(int j=0;j<count;j++)
          {              
                  cb.setChecked(false);
          }
      }
 }

 class ViewHolder 
 {
      TextView textview , textIndexId;
      CheckBox checkbox;
      int id;
 }
用户名

公共类ImageAdapter扩展BaseAdapter {私有LayoutInflater mInflater; 私有上下文mContext; 公共ImageAdapter(上下文上下文){mContext = context; } public int getCount(){返回计数;} public Object getItem(int position){返回位置;} public long getItemId(int position){返回位置;} public View getView(final int position,View convertView,ViewGroup parent){ViewHolder持有者;如果(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.state_info,null);

                holder = new ViewHolder();                                      
                holder.textview = (TextView) convertView.findViewById(R.id.thumbImage);                                              
                holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox); 

                convertView.setTag(holder);

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

           convertView.setTag(holder);

           //holder.checkbox.setId(position);
           holder.textview.setId(position);

           holder.checkbox.setId(position);
           holder.checkbox.setOnClickListener(new OnClickListener() {
               @Override
               public void onClick(View v) 
               {
                   for (int i = 0; i < count; i++) 
                   {
                       if (v.getId() == i) 
                       {
                           thumbnailsselection[i] = true;
                           Log.v("check", ""+position);

                       } 
                       else 
                       {
                           thumbnailsselection[i] = false;
                       }
                   }
                   notifyDataSetChanged();
               }
           });

           if (thumbnailsselection[position]) 
           {
               holder.checkbox.setChecked(true);
           } 
           else 
           {
               holder.checkbox.setChecked(false);
           }

           holder.textview.setText(items.get(position).getName());

           holder.checkbox.setChecked(thumbnailsselection[position]);
           holder.id = position;
           return convertView;

      }          

 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Dialog Android中对复选框进行单选?

如何在复选框和单选按钮中使用长标签包装并使用CSS适当缩进?

如何在React钩子中使用CheckAll复选框创建复选框?

如何在反应中使用多个复选框并收集选中的复选框

如何在Materialize表中使用复选框

如何在PHP中使用html复选框插入INTO

如何在reactjs中使用antd多个复选框?

如何在复选框栏杆中使用枚举

如何在React中使用复选框形式?

如何在复选框中使用 css

如何在Python中使用Selenium选中复选框

如何在表格php中使用复选框

如何在我的 WordPress 网站中使用复选框?

如何在 jetpack compose 中使用复选框控件?

如何在ObjectListView中使复选框列的行为类似于单选按钮?

单击复选框后,如何在Vue.js中使用v-on传递复选框ID?

如何使用复选框取消选中单选按钮

如何在css中使用复选标记作为复选框

如何在Android中使用api将多个选定的复选框值传递给服务器?

如何在aspxgridview中使复选框可编辑?

如何在离子框架中使ios的复选框方形?

如何在android复选框上调用函数复选框?

如何在angularjs中使用json对象生成复选框

如何在Swing Java的复选框中使用全选选项?

如何在PHP发出的表格行中使用JavaScript检查所有复选框

如何在 Python 中使用 Selenium WebDriver 根据 html 选择复选框

如何在 onClick 按钮中使用 javascript 检查所有复选框?

如何在下拉菜单中使用复选框?

我如何在PHP中使用href传递复选框值?