我的自定義列表視圖中的複選框偵聽器僅適用於第一個複選框。我認爲這與getView()中的位置有關。我附上我的代碼與這個問題,請建議我解決這個問題。OnCheckChanged偵聽器僅適用於自定義列表視圖中的第一個複選框
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if(convertView==null)
{
convertView = inflater.inflate(R.layout.custom_list, null);
holder = new ViewHolder();
holder.txtViewTitle = (TextView) convertView.findViewById(R.id.title_text);
holder.txtViewDescription = (TextView)convertView.findViewById(R.id.description_text);
holder.cb=(CheckBox) convertView.findViewById(R.id.cb);
convertView.setTag(holder);
holder.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
String Channel=holder.txtViewTitle.getText().toString();
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(position==0)
{
//works
}
else
if(position==1)
{
//doesn't work
}
});
}
else
{
holder=(ViewHolder)convertView.getTag();
}
holder.txtViewTitle.setText(title[position]);
holder.txtViewDescription.setText(description[position]);
holder.txtViewDescription.setFocusable(false);
holder.txtViewTitle.setFocusable(false);
return convertView;
}
使用下面的鏈接來解決烏爾問題.. .. http://stackoverflow.com/questions/7738527/getting-an-issue-while-checking-the-dynamically-generated-checkbox-through-list – himanshu 2012-02-16 06:49:16