Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2017 14:20
What would you like to do?
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(;
holder.checkBox = (CheckBox) convertView.findViewById(;
} else {
holder = (ViewHolder) convertView.getTag();
if (holder.checkBox != null) {
holder.checkBox.setVisibility(showCheckboxes ? View.VISIBLE : View.GONE);
if (showCheckboxes) {
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