2013-08-19 126 views
0

我想在自定義列表視圖中使用單選複選框。這裏是我的自定義適配器中的getview方法。自定義列表視圖中的單選複選框

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = (LayoutInflater) context 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View rowView =convertView; 
    ViewHolder holder; 

    if (rowView == null) { 
    rowView = inflater.inflate(R.layout.row_timeslot, parent, false); 
    holder = new ViewHolder(); 
    holder.title = (TextView) rowView.findViewById(R.id.textView2); 
    holder.layout=(RelativeLayout)rowView.findViewById(R.id.relativeLayout1); 
    holder.check=(org.holoeverywhere.widget.CheckBox)rowView.findViewById(R.id.checkBox1); 


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

    HashMap<String, String> trends_data= new HashMap<String, String>(); 
    trends_data = trendsobj.get(position); 


    holder.check.setId(position); 



    holder.check.setChecked(checkarry[position]); 


    //for managing the state of the boolean 
    //array according to the state of the 
    //CheckBox 



    holder.check.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      if (((CheckBox) v).isChecked()) 
      { 
       checkarry[position] = true; 

      } 


      else 
      { 
       checkarry[position] = false; 

      } 
     } 
    }); 


    holder.title.setText(trends_data.get(BookingActivity.KEY_TIME_TITLE)); 




    return rowView; 
} 

我想取消勾選複選框,當另一個複選框被選中。任何幫助,將不勝感激。謝謝。

+0

閱讀有關'RadioButton'對於這種方式,請 –

+0

@Lia Pronina:謝謝,我知道有關無線電button.But我的目的,我們需要使用無線電集團,而不是單選按鈕。這個廣播組是可能與列表視圖? –

回答

0

寫這一行 holder.check.setChecked(checkarry [position]);

上點擊監聽器之後,我認爲會做

相關問題