Mayur Raval Mayur Raval - 1 year ago 103
Android Question

Android hide and show checkboxes in custome listview on button click

i use the adapter which is given below. i explain in the figures. figures is just for referances.
i use textview and checkbox in for single line. textviews should appear and checkboxes hide initially.after on button press checkbox should appear and textview remain same.please help me.thanks in advance..

enter image description here
enter image description here

public class Adapter extends ArrayAdapter<SectionsModel>{

private ArrayList<SectionsModel> list;
public Adapter(Context context, int resource, ArrayList<SectionsModel> objects) {
super(context, resource, objects);
this.list = new ArrayList<SectionsModel>();

ViewHolder v = new ViewHolder();
public void setcheckbox() {

Log.d("viewholser" + v, "checkbox" + v.selected);



public class ViewHolder {
public TextView setting;
public CheckBox selected;

public View getView(final int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;
if (convertView == null) {

LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

convertView = vi.inflate(R.layout.menu_frame_child, null);
holder = new ViewHolder();

holder.setting = (TextView) convertView.findViewById(;
holder.selected = (CheckBox) convertView.findViewById(;

// holder.selected.setVisibility(View.INVISIBLE);



holder.selected.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
SectionsModel _state = (SectionsModel) cb.getTag();
} else {
holder = (ViewHolder) convertView.getTag();

SectionsModel section = list.get(position);



return convertView;

public int getCount()
return super.getCount();

public int getPosition(SectionsModel item) {

return super.getPosition(item);


In getview i just add following code
AppConstants.ischeckboxvisible is variable where Appconstants is class and ischeckboxvisible is public static variable on that class. initially this variable is false

if (!AppConstants.ischeckboxvisible)
if (AppConstants.ischeckboxvisible)

Answer Source

Add another attribute to your SectionModel as inEditMode, and set it to true at all items in your array when user clicks edit, and call notifyDataSetChanged on your adapter.

In Adapter check that flag on every item and make them visible or invisible.