开发者

Bulid URL from checkbox values (array) Android

My main view has 4 checkboxes and a submit button. I am trying to build a url from the values selected on the checkboxes. Below is the base of my page I am not sure how to program the collection of the checkbox values and submit to my function that does an http call with the checkbox values in the url query.

Any help would be great.

package com.flash_tattoo;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import com.flash_tattoo.DataCall;

public class flash_tattoo extends Activity {

    private Button get_images;

    private CheckBox cb1, cb2, cb3, cb4;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
 开发者_JAVA技巧       super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        get_images = (Button)findViewById(R.id.get_images);

            CheckBox[] setOfCheckBoxes = new CheckBox[]
           {
         (CheckBox) findViewById(R.id.checkBox1);
         (CheckBox) findViewById(R.id.checkBox2);        
         (CheckBox) findViewById(R.id.checkBox3);
         (CheckBox) findViewById(R.id.checkBox4);
          };
       for(int i = 0; i < setOfCheckBoxes.length; i++){
       setOfCheckBoxes[i].setOnCheckedChangeListener(BasicCheckListener);
       }


        get_images.setOnClickListener(new OnClickListener() {         
            @Override
            public void onClick(View v){
**//HERE IS WHERE I WANT TO GET THE VALUES OF THE CHECKBOX BUILD AN ARRAY AND THEN PASS THE ARRAY TO MY FUNCTION.**
                String Image_data = DataCall.getJSON();

                  } 
        });

    }

}


if(cb1.isChecked())
{

  String url = cb1.getText(); //i assumed you have |x| Text <--- checkbox form
}else if (cb2.isChecked())
{
    String url = cb2.getText();
}
...and so on...

But why dont you implement setOnCheckedChangeListener() method for each checkbox and whenever any checkbox is checked you get the text from the checkbox by doing only one test if(checkbox.isChecked()) checkbox.getText(), instead of doing tons of ifs

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜