private class EfficientAdapter extends BaseAdapter implements ListView.OnScrollListener
{
private LayoutInflater mInflater;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return c.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.customcontactlist, null);
holder = new ViewHolder();
holder.txtName = (CheckedTextView) convertView.findViewById(R.id.TextView01);
holder.txtNumber = (TextView) convertView.findViewById(R.id.TextView00);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (hashtable.contains(position)) {
holder.txtName.setChecked(true);
}else{
holder.txtName.setChecked(false);
}
return convertView;
}
class ViewHolder {
CheckedTextView txtName;
TextView txtNumber;
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}
и в Деятельности
l1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
EfficientAdapter.ViewHolder holder;
holder = (EfficientAdapter.ViewHolder) arg1.getTag();
if(holder.txtName.isChecked()){
holder.txtName.setChecked(false);
}else{
holder.txtName.setChecked(true);
}
}
});