开发者

Getting multiple checkbox values in android?

new Android developer here. I'm doing a form that let's users set up some search criteria before searching in a SQLite db. Part of the form includes some checkboxes. How do I go about their values in a "best practice" sense?

I'm used to doing PHP, so I would set up a method that returns an array or object with all the values, and then call that inside the 'onClick' method, but is that also a good idea in Java?

My code looks like this:

    // Setup a listener, and event handler for the onClick event of the button
    buttonFind.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            String text = "Button clicked";
            int duration = Toast.LEN开发者_如何学JAVAGTH_SHORT;
            Context context = getApplicationContext();

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    });


It's probably better to give more details in your question. You don't show anywhere in your code where you define your checkbox... so i'm going to make some assumptions:

I'll assume that somewhere in your onCreate() method of your activity you have something that looks like this:

CheckBox myCheckbox = (Checkbox) findViewById(R.id.my_checkbox);

If you want to find out if the checkbox is checked or not from your button's onClick() method (since you posted it above), you can do something like this:

boolean isMyCheckboxChecked = myCheckbox.isChecked();

Hope that works out for you. Next time try to be more clear in your questions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜