将multiheckbox值传递给另一个活动

时间:2015-01-14 02:06:31

标签: android

让我再试一次,用更好的措辞。我很陌生;我试图将复选框的值结果传递给另一个活动。我已经尝试了几种不同的方法而没有成功,我会感激一些方向。 我知道如何用结果制作“Toast”,这不是我想要的。我希望复选框结果将显示在另一个活动的textview中。如果有人可以帮助我提供一些关于如何完成这项任务的提示,我将不胜感激,我很抱歉打扰所有人这些没有挑战性的问题。  我已经阅读了几本书并观看了一些教程,但我的技能仍然缺乏。这些书与教程(按钮和布局等)一样重复和冗余。

    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) {
            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();
                }
                Intent myIntent=new Intent(getApplication(),ApplianceMessage.class);
                myIntent.putExtra("chbxshirleys", vendor);
                myIntent.putExtra("chbxdianas", vendor);
                myIntent.putExtra("chbxzoila", vendor);
                myIntent.putExtra("chbxsheila", vendor);
                myIntent.putExtra("chbxrobert", vendor);
                myIntent.putExtra("chbxsam", vendor);
                myIntent.putExtra("chbxcamren", vendor);
                myIntent.putExtra("chbxricks", vendor);
                startActivity(myIntent);
        }       
        });

}

新活动

public class ApplianceMessage extends Activity {


private TextView tvname = (TextView)findViewById(R.id.tvname);
private EditText etname = (EditText)findViewById(R.id.etname);
private TextView tvcity = (TextView)findViewById(R.id.tvcity);
private EditText etcity = (EditText)findViewById(R.id.etcity);
private TextView tvtime = (TextView)findViewById(R.id.tvtime);
private EditText ettime = (EditText)findViewById(R.id.ettime);
private RadioButton rbutton =(RadioButton)findViewById(R.id.rburgent);
private TextView tvproblem = (TextView)findViewById(R.id.rburgent);
private EditText etproblem = (EditText)findViewById(R.id.etproblem);
private TextView tvvendor = (TextView)findViewById(R.id.vendorlist);
private Button msendbutton;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.appliance_message);

    final Bundle extras = getIntent().getExtras();
    extras.getInt("chbxshirleys");
    extras.getInt("chbxdianas");
    extras.getInt("chbxzoila");
    extras.getInt("chbxshiela");
    extras.getInt("chbxrobert");
    extras.getInt("chbxcamren");
    extras.getInt("chbxsam");
    extras.getInt("chbxricks");

    msendbutton = (Button)findViewById(R.id.sendbutton);
    msendbutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            tvname.setText("Insert Name");
            etname.setText("");
            tvcity.setText("City Name");
            etcity.setText("");
            tvtime.setText("Time");
            ettime.setText("");
            tvproblem.setText("Problem");
            etproblem.setText("");

    }
});

    }

}

2 个答案:

答案 0 :(得分:1)

在您的第一项活动中:

Intent i=new Intent(YourClassName.this,ApplianceMessage.class);
i.putExtra("selected",vendor);
startActivity(i);

在你的第二个活动中:

String selecteditem=getIntent().getExtras().getString("selected");
textview.setText(selecteditem);

答案 1 :(得分:0)

您在意图中添加了String Extra。得到它:

getIntent().getStringExtra("chbxshirleys");
....