Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull final ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.titleNameView = (TextView) convertView.findViewById(R.id.text1);
holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.titleNameView.setText(filteredData[position].getName());
if (holder.checkBox != null) {
holder.checkBox.setVisibility(showCheckboxes ? View.VISIBLE : View.GONE);
if (showCheckboxes) {
holder.checkBox.setChecked(filteredData[position].isChecked());
holder.checkBox.setOnClickListener(getOnClickListener(position, (ListView) parent));
}
holder.titleNameView.setOnClickListener(getOnClickListener(position, (ListView) parent));
}
return convertView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment