我需要的是我在EditText campoempresa和camporesponsavel上编写的内容,我需要在DiagnosticoActivity上显示,但该程序显示为空或不显示任何内容。我正在使用Firebase数据库,还有另一种方法吗?
FirstActivity
@Override
public void onClick(View v) {
String textoequipe = campoequipe.getText().toString();
String textoempresa = campoempresa.getText().toString();
String textosetor = camposetor.getText().toString();
String textoresponsavel = camporesponsavel.getText().toString();
Intent myintent = new Intent(NovoActivity.this, DiagnosticoActivity.class);
Bundle bundle = getIntent().getExtras();
Bundle.getString("campoempresa", textoempresa);
Bundle.getString("camporesponsavel", textoresponsavel);
startActivity(myintent);
if ( !textoequipe.isEmpty()){
if ( !textoempresa.isEmpty()){
if ( !textosetor.isEmpty()){
if ( !textoresponsavel.isEmpty()){
informações = new Informações();
informações.setEquipe( textoequipe );
informações.setEmpresa( textoempresa );
informações.setSetor( textosetor );
informações.setResponsavel( textoresponsavel );
informações.salvar();
第二活动
public class DiagnosticoActivity extends AppCompatActivity {
private Button btbloco;
private Button btanotacoes;
private Button btfotos;
private ImageButton btvnovo;
private ImageButton btvfinalizar;
private TextView EmpresaResponsavel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
EmpresaResponsavel = findViewById(R.id.EmpresaResponsavel);
Intent myintent = getIntent();
String textoempresa = myintent.getStringExtra("campoempresa");
String textoresponsavel = myintent.getStringExtra("camporesponsavel");
EmpresaResponsavel.setText(textoempresa + " - " + textoresponsavel);
答案 0 :(得分:1)
开始活动:
startActivity(new Intent(CurrentActivity.this, AnotherActivity.class).putExtra("campoempresa", textoempresa).putExtra("camporesponsave1", textoresponsave1));
获取值:
Intent i = getIntent();
String v1 = i.getStringExtra("campoempresa");
String v2 = i.getStringExtra("camporesponsave1");
答案 1 :(得分:0)
您有2个我可以看到的问题...
在第一个活动中,使用Bundle bundle = getIntent()。getExtra(“ bundle”)来检索bundle,然后使用bundle.getString(“ campoempresa”)来获取字符串的值...
在第二个活动中,您没有将捆绑软件附加到意图上……
使用myIntent.putExtra(bundle)
创建捆绑包并开始活动:
Intent myIntent = new Intent(this, DiagnosticsoActivity.class);
Bundle bundle = new Bundle();
bundle.putString("campoempresa", textoempresa);
bundle.putString("camporesponsave1", textoresponsave1);
myIntent.putExtra("bundle", bundle);
startActivity(myIntent);
获取活动中的捆绑包:
Bundle bundle = getIntent().getExtra("bundle");
String textoempresa = bundle.getString("campoempresa");
String textoresponsave1 = bundle.getString("camporesponsave1")