如何将数据发送到新的Andr​​oid活动如何将、到新、数据、oid

2023-09-12 06:09:12 作者:谁的青春不二逼

我的工作,它收集用户的选择(从复选框),并将其发送到一个新的活动(当按钮是pressed)的应用程序。在新的活动,新的数据将被收集(EDITTEXT)和接收数据+新收集的数据将被合并,并通过电子邮件发送。

当我preSS 1号按钮,将复选框数据发送到新的活动,我得到一个错误

  

应用程序意外终止

下面是code:

 公共无效的onClick(视图v)
{

                   cakeDataformated();
                   //将数据(复选框)转换为字符串
                   串fianlformatedData = cakeDataformated();

                    意图I =新的意图(这一点,PersonData.class);
                    i.putExtra(cakedata,fianlformatedData);
                    startActivity(ⅰ);

    }
 

和复选框转换方法是:

 公共字符串cakeDataformated(){
    // TODO自动生成方法存根

    布尔checkyStatus1 = checky1.isChecked();
    布尔checkyStatus2 = checky2.isChecked();
    布尔checkyStatus3 = checky3.isChecked();
    布尔checkyStatus4 = checky4.isChecked();
            //读取复选框数据
    字符串形式= finalFormUsingFollowing(checkyStatus1,checkyStatus2,checkyStatus3,checkyStatus4);
        //转换复选框响应到消息并保存为
            //一个名为字符串形式
            //例如:选择蛋糕:cake1,cake3
    返回的形式;


}
 

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

解决方案

  RadioGroup中RadioGroup中=(RadioGroup中)本
            .findViewById(R.id.radio_group);
    RadioGroup中
            .setOnCheckedChangeListener(新RadioGroup.OnCheckedChangeListener(){

                @覆盖
                公共无效onCheckedChanged(RadioGroup中RadioGroup中,INT ID){
                    最后单选按钮单选按钮=(单选)RadioGroup中
                            .findViewById(ID);

                    。字符串selectedText = radioButton.getText()的toString();
                    意图I =新的意图(这一点,PersonData.class);
                    i.putExtra(cakedata,selectedText);
                    startActivity(ⅰ);
                }

            });
 

I am working on an application that gathers user selection (from a checkbox) and sends it to a new activity (when a button is pressed ). In the new activity, a new data will be collected (editText) and the received data + newly collected data will be combined and sent via email.

When I press the 1st button to send the checkbox data to the new activity, I get an error

The application has stopped unexpectedly

Here is the code:

 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);

    }

and the check box conversion method is:

 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 ;


}

So, if there are any errors please tell me.

解决方案

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);
                }

            });