我正在尝试创建一个按钮,用于选择/取消选择ListView
中的所有项目。到目前为止,我的经理为所有项目创建了复选框,但现在我必须创建一个按钮来选择所有项目。我在监听器中使用了Metadata类来获取复选框。
这是我的适配器:
public class ResultsAdapter extends DataBufferAdapter<Metadata>{
Context context;
public ResultsAdapter(Context context) {
super(context, R.layout.list_item);
this.context = context;
}
private class ViewHolder {
TextView txtView;
CheckBox checkBox;
CheckBox selectAllChk;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.txtView = (TextView) convertView.findViewById(R.id.textView1);
holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
holder.selectAllChk = (CheckBox) convertView.findViewById(R.id.selectAllButton);
convertView.setTag(holder);
final ViewHolder finalHolder = holder;
holder.checkBox.setOnClickListener(new View.OnClickListener() {
/* private Context applicationContext;
public Context getApplicationContext() {
return applicationContext;
}*/
@Override
public void onClick(View v) {
Metadata metadata = getItem(position);
finalHolder.txtView.setText(metadata.getTitle());
}
});
} else {
holder = (ViewHolder)convertView.getTag();
}
return convertView;
}
}