gpt4 book ai didi

android - 将多选框值传递给另一个 Activity

转载 作者:行者123 更新时间:2023-11-30 02:25:36 25 4
gpt4 key购买 nike

让我用更好的措辞再试一次。我对此很陌生;我正在尝试将复选框的值结果传递给另一个 Activity 。我尝试了几种不同的方法但没有成功,我将不胜感激。我知道如何用结果做一个“ toast ”,那不是我想要的。我希望复选框结果显示在另一个 Activity 的 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);
}
});

}

新 Activity

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

}
});

}

}

最佳答案

在您的第一个 Activity 中:

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

在您的第二个 Activity 中:

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

关于android - 将多选框值传递给另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27934737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com