0

我需要的是我在 EditText campoempresa 和 camporesponsavel 上写的,我需要在 DiagnosticoActivity 中显示,但程序显示 null 或没有。我正在使用 Firebase 数据库,还有其他方法吗?

第一活动

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

2 回答 2

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");
于 2018-12-09T23:11:05.190 回答
0

你有两个我可以看到的问题......

在第一个活动中,使用 Bundle bundle = getIntent().getExtra("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")
于 2018-12-09T22:51:46.893 回答