-1

I have created custom adapter and two layouts files the first layout is fragment view which contains ListView and Button

the second layout contains items which will be represented in the ListView

So

I want when the Checkbox is check make Button visible

All of these operations will be done in my custom adapter class

This is myCustom Adapter

Updated

public class LampControllerAdapter extends BaseAdapter {
Context mContext;
List<LampModel> mLampModels;
HashMap<Long,LampModel> selection;
Button sC;

  public LampControllerAdapter(Context context, ArrayList<LampModel> lampList) {

    mContext = context;
    mLampModels = lampList;
    selection = new HashMap<Long,LampModel>();
    LayoutInflater in = (LayoutInflater) LayoutInflater.from(context);

    View v = in.inflate(R.layout.fragment_home,null);
   sC = (Button)v.findViewById(R.id.selection_control);



}

@Override
public int getCount() {
    return mLampModels.size();
}

@Override
public Object getItem(int i) {
    return mLampModels.get(i);
}

@Override
public long getItemId(int i) {
    return 0;
}

@Override
public View getView(final int i, View view, ViewGroup parent) {

    ViewHolder holder;
    final LampModel model = (LampModel) getItem(i);
    if (view == null) {
        // Inflating The Layout
        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        view = inflater.inflate(R.layout.lamp_controller_item, parent, false);
        holder = new ViewHolder();

        holder.name = (TextView) view.findViewById(R.id.lamp_item_name);
        holder.description = (TextView) view.findViewById(R.id.lamp_item_description);
        holder.select = (CheckBox) view.findViewById(R.id.lamp_item_select);
        view.setTag(holder);

    } else {
        holder = (ViewHolder) view.getTag();
    }


    holder.name.setText(model.getName());
    holder.description.setText(model.getDescription());
    holder.select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

            if(b){
                selection.put(model.getId(),model);
            }else {
                selection.remove(model.getId());
            }

            if(selection.size() > 0){
                Toast.makeText(mContext, "Not Empty", Toast.LENGTH_SHORT).show();
                sC.setVisibility(View.GONE);
            }else {
                Toast.makeText(mContext, "Empty", Toast.LENGTH_SHORT).show();
            }

        }
    });


    return view;
}


class ViewHolder {
    TextView name, description;
    CheckBox select;
    Switch aSwitch;
}

}

Ali Turki
  • 1,265
  • 2
  • 16
  • 21

1 Answers1

2

try this

CheckBox chkBox = ( CheckBox ) findViewById( R.id.chkBox );
chkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        if ( isChecked )
        {
            // perform your action here
        }

    }
});
AskNilesh
  • 67,701
  • 16
  • 123
  • 163