0

I'm trying to implement clearing all the check marks of check boxes on single button click, code seems okay for me but it isn't working. Checkboxes is in different layout...in my present activity I'm inflating the checkboxes and doing setChecked(false)(which is not working)..is there any another way?

Button clearbtn1 = (Button) findViewById(R.id.clearbtn);
        clearbtn1.setOnClickListener(new OnClickListener() {
            @Override

            public void onClick(View v) {



                LayoutInflater inflater_example = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                View v1= inflater_example.inflate(R.layout.profile, null); 
                CheckBox checkBox = (CheckBox) v1.findViewById(R.id.checkBox1);
                checkBox.setChecked(false); 
        }
        });

Any help would be appreciated.

19
  • inflating the layout will not work.. you are not setting this inflated view to your layout anywhere.. so the change won't reflect. Where is the checkbox in ? your parent layout? Commented Jan 4, 2013 at 5:12
  • parent layout is different and check box is in different layou..can u suggets what to do Commented Jan 4, 2013 at 5:13
  • checkbox is displayed in the same activity ? Commented Jan 4, 2013 at 5:14
  • yes checkbox is displayed in same activity Commented Jan 4, 2013 at 5:15
  • @teekib improve your question its difficult to answer due lack of information. Commented Jan 4, 2013 at 5:17

2 Answers 2

1

your adapter has these views that you want to effect. standard OOP principles dictate that you make adapter methods to go about it. judging from your adapter technique and how it deftly combats convertView to persist checkbox states, i'd think the method would be self-evident. simply set the boolean flags that determine their states and refresh the adapter. here's a sample adapter method, that you can call from the button's OnClickListener

private void clearChecks() {
    for (int i = 0; i < Constants.checkBoxState.length; i++) {
        Constants.checkBoxState[i] = false;
    }
    notifyDataSetChanged();
}
Sign up to request clarification or add additional context in comments.

1 Comment

exactly .. implemented the same thing as below..thanks a ton private boolean selectStatus() { boolean result = true; for (int i = 0; i < Constants.checkBoxState.length; i++) { if (Constants.checkBoxState[i] == true) { return false; } } return result; } }
1

Just clear all the checkbox states in Constants and notify or reset adapter for the change to reflect.

Button clearbtn1 = (Button) findViewById(R.id.clearbtn);
    clearbtn1.setOnClickListener(new OnClickListener() {
        @Override

        public void onClick(View v) {
          for(int i=0;i < Constants.checkBoxState.length; i++)      
             Constants.checkBoxState[i] = false;

          listAdapter.notifyDataSetChanged();

    }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.