如何将数据发送到新的Android活动

时间:2012-11-28 00:03:22

标签: java android android-activity

我正在开发一个应用程序,它收集用户选择(从复选框)并将其发送到新活动(按下按钮时)。在新活动中,将收集新数据(editText),并将收到的数据+新收集的数据合并并通过电子邮件发送。

当我按第一个按钮将复选框数据发送到新活动时,我收到错误:

  

应用程序意外停止

以下是代码:

 public void onClick(View v) 
{

                   cakeDataformated();
                   // to convert the data (checkBox) to a string
                   String fianlformatedData = cakeDataformated();

                    Intent i = new Intent(this, PersonData.class);  
                    i.putExtra("cakedata", fianlformatedData);
                    startActivity(i);

    }

并且复选框转换方法是:

 public String cakeDataformated () {
    // TODO Auto-generated method stub

    boolean checkyStatus1 = checky1.isChecked();
    boolean checkyStatus2 = checky2.isChecked();
    boolean checkyStatus3 = checky3.isChecked();
    boolean checkyStatus4 = checky4.isChecked();
            // to read the checkbox data
    String form = finalFormUsingFollowing (checkyStatus1 ,checkyStatus2 ,checkyStatus3 , checkyStatus4 );
        //  to convert the check box response into a message and save it as 
            //  a string called form
            // example : cakes selected are : cake1 , cake3 
    return form ;


}

所以,如果有任何错误,请告诉我。

1 个答案:

答案 0 :(得分:0)

RadioGroup radioGroup = (RadioGroup) this
            .findViewById(R.id.radio_group);
    radioGroup
            .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(RadioGroup radioGroup, int id) {
                    final RadioButton radioButton = (RadioButton) radioGroup
                            .findViewById(id);

                    String selectedText = radioButton.getText().toString();
                    Intent i = new Intent(this, PersonData.class);
                    i.putExtra("cakedata", selectedText);
                    startActivity(i);
                }

            });