2013-08-05 205 views
0

我有一个列表包含一些复选框,如何可以找出哪个复选框被点击。 我尝试itemClickListener()但没有回应我,自定义列表单击复选框

+0

'onItemClickListener'设置在ListView的整个行视图上,您​​必须区分复选框上的点击,以便您行点击监听器不会干扰。 http://www.mysamplecode.com/2012/07/android-listview-checkbox-example.html –

+0

我尝试使用Cursor添加,但在本例中使用list.add() –

+0

http://lalit3686.blogspot 。在/ 2012/06 /今天我-AM持续到演出 - 如何对deal.html –

回答

0

对于这一点,你必须通过extendind 的BaseAdapter类,然后在getview(创建自己的适配器)的方法该adpater膨胀的布局,并获得该复选框,并为此编写监听器..

0

创建你自己的ArrayAdapter,并在你的getView(...)方法中实现你的cckckbox监听器。

getView为您提供列表中的项目位置,以便您可以执行任何所需的操作。

这里是如何ONW arrayadapter创建你的为例:

How to use ArrayAdapter<myClass>

0
@Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     View view; 
     if (convertView == null) { 
      LayoutInflater inflater = MyPINsActivity.this 
        .getLayoutInflater(); 
      view = inflater.inflate(R.layout.row_list_mypins, null); 
     } else { 
      view = convertView; 
     } 

     final CheckBox cb = (CheckBox) view.findViewById(R.id.cb); 
     //here you can save the position as tag to CheckBox, and get where you want 
     cb.setTag(position); 

     cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       if(isChecked){ 
        //get the positon of CheckBox by using mCheckBox.getTag() 
        String positon = cb.getTag().toString(); 
        Log.e(TAG, "positon: "+positon); 
       } 
      } 
     }); 
    } 
相关问题