0

我正在开发由edittext 字段和复选框组成的应用程序。如果用户只选择了其中的几个,那么如何从字段中获取这些文本值。

public class ExtraFields extends Activity{

    Button btnSubmit;

    int noOfFields=0;



    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes bar

        setContentView(R.layout.extra_fields);

        btnSubmit = (Button) findViewById(R.id.submit);

        btnSubmit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                noOfFields = 0;

                send();
            }
        });
    }




    protected void send(){

    }


}
4

3 回答 3

4

像这样

    cb= (CheckBox)findViewById(R.id.checkbox1);
     if(cb.isChecked())
EditText t = (EditText) findViewById(R.id.edit4);
String a = t.getText().toString();
     }
于 2013-07-19T13:32:33.997 回答
2

单击复选框时,您可以获得文本

if(checkbox1.isChecked()) {
EditText et1 = (EditText) findViewById(R.id.edittext1);
String one = et1.getText().toString();   
}
于 2013-07-19T13:37:13.303 回答
0

您可以从 EditText 获取文本,如下所示:

CheckBox check1 = (CheckBox) findViewById(R.id.checkbox1);
Checkbox check2 = (Checkbox) findViewById(R.id.checkbox2);
if (check1.isChecked()) {
    EditText myEditText = (EditText) findViewById(R.id.edit_text_1);
    String string1 = myEditText.getText().toString();
}
if (check2.isChecked()) {
    EditText myEditText2 = (EditText) findViewById(R.id.edit_text_2);
    String string2 = myEditText2.getText().toString();
}
于 2013-07-19T13:31:47.060 回答