传递复选框结果

时间:2015-01-12 14:37:01

标签: android

我很陌生;我试图将复选框的结果传递给另一个活动。我已经尝试了几种不同的方法而没有成功,我会感激一些方向。请任何帮助都会很棒。谢谢

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.appliance);

    final CheckBox chbxshirleys = (CheckBox)findViewById(R.id.checkboxshirleys);
    final CheckBox chbxdianas = (CheckBox)findViewById(R.id.checkboxdianas);
    final CheckBox chbxzoila = (CheckBox)findViewById(R.id.checkboxzoila);
    final CheckBox chbxsheila = (CheckBox)findViewById(R.id.checkBoxSheila);
    final CheckBox chbxrobert = (CheckBox)findViewById(R.id.checkBoxrobert);
    final CheckBox chbxsam = (CheckBox)findViewById(R.id.checkBoxsam);
    final CheckBox chbxcamren = (CheckBox)findViewById(R.id.checkBoxcamren);
    final CheckBox chbxricks = (CheckBox)findViewById(R.id.checkBoxricks);
    final Button vendorbutton = (Button)findViewById(R.id.vendorbutton);

    vendorbutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent (getApplicationContext(),ApplianceMessage.class);
            Bundle extras = new Bundle();
            extras.putString("shirleys", null);
            extras.putInt("vendor", 0);
            myIntent.putExtras(extras);

            String vendor ="";
            if (chbxshirleys.isChecked())
            {
                vendor += chbxshirleys.getText();

            }
            if (chbxdianas.isChecked())
            {
                vendor += chbxdianas.getText();
            }
            if (chbxzoila.isChecked())
            {
                vendor += chbxzoila.getText();
            }
            if (chbxsheila.isChecked())
            {
                vendor += chbxsheila.getText();
            }
            if (chbxrobert.isChecked())
            {
                vendor += chbxrobert.getText();
            }
            if (chbxsam.isChecked())
            {
                    vendor += chbxsam.getText();
            }
            if (chbxcamren.isChecked())
            {
                    vendor += chbxcamren.getText();
            }
            if (chbxricks.isChecked())
            {
                vendor += chbxricks.getText();
            }
        }
    });
}

2 个答案:

答案 0 :(得分:0)

我认为你可以使用

intent.putExtra(" String name",chbxshirleys.isChecked());

在Activity get boolean value

答案 1 :(得分:0)

首先,请从这里了解更多关于android的复选框: http://developer.android.com/guide/topics/ui/controls/checkbox.html 举个好例子,你可以看一个: http://www.mkyong.com/android/android-checkbox-example/ 并且为了传递结果,其他活动使用额外的活动。