0

我正在开发一个 android 应用程序,用户填写一个活动,然后另一个活动并生成一个 word docx 报告。

我正在使用附加功能将字符串从第一个活动传递到第二个活动。

我的问题是我所有的字符串都具有最后一个字符串的值放入附加项中。这是我的代码:

活动一:

Intent pelle = new Intent(VGP1.this, Pelle.class);
Bundle extras = new Bundle();
extras.putString(eEntreprise, sEntrepriseComplete);
extras.putString(eAdresse, sAdresseComplete);
extras.putString(eIdVerificateur, editTextIdVerificateur.getText().toString());
extras.putString(eNomProprio, editTextNomProprio.getText().toString());
extras.putString(eAdresseProprio, editTextAdresseProprio.getText().toString());
extras.putString(eNomEntreprise, editTextNomEntreprise.getText().toString());
extras.putString(eAdresseEntreprise, editTextAdresseEntreprise.getText().toString());
extras.putString(eJourVerif, sJourVerif);
extras.putString(eMoisVerif, sMoisVerif);
extras.putString(eAnneeVerif, sAnneeVerif);
pelle.putExtras(extras);
startActivity(pelle);

活动二:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pelle);

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        eEntreprise2 = extras.getString(VGP1.eEntreprise);
        eAdresse2 = extras.getString(VGP1.eAdresse);
        eIdVerificateur2 = extras.getString(VGP1.eIdVerificateur);
        eNomProprio2 = extras.getString(VGP1.eNomProprio);
        eAdresseProprio2 = extras.getString(VGP1.eAdresseProprio);
        eNomEntreprise2 = extras.getString(VGP1.eNomEntreprise);
        eAdresseEntreprise2 = extras.getString(VGP1.eAdresseEntreprise);
        eJourVerif2 = extras.getString(VGP1.eJourVerif);
        eMoisVerif2 = extras.getString(VGP1.eMoisVerif);
        eAnneeVerif2 = extras.getString(VGP1.eAnneeVerif);
    }

所有值“xxxxx2”都取eAnneeVerif的值,我不明白为什么。

先感谢您。

4

1 回答 1

1

试试这个代码:

在您的Activity 1发送数据中,如下所示:

Intent pelle = new Intent(VGP1.this, Pelle.class);
pelle.putExtra("eEntreprise", sEntrepriseComplete);
pelle.putExtra("eAdresse", sAdresseComplete);
pelle.putExtra("eIdVerificateur", editTextIdVerificateur.getText().toString());
pelle.putExtra("eNomProprio", editTextNomProprio.getText().toString());
pelle.putExtra("eAdresseProprio", editTextAdresseProprio.getText().toString());
pelle.putExtra("eNomEntreprise", editTextNomEntreprise.getText().toString());
pelle.putExtra("eAdresseEntreprise", editTextAdresseEntreprise.getText().toString());
pelle.putExtra("eJourVerif", sJourVerif);
pelle.putExtra("eMoisVerif", sMoisVerif);
pelle.putExtra("eAnneeVerif", sAnneeVerif);
startActivity(pelle);

在您的Activity 2获取数据中,如下所示:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pelle);

    Intent intent = getIntent();
    eEntreprise2 = intent.getStringExtra("eEntreprise");
    eAdresse2 = intent.getStringExtra("eAdresse");
    eIdVerificateur2 = intent.getStringExtra("eIdVerificateur");
    eNomProprio2 = intent.getStringExtra("eNomProprio");
    eAdresseProprio2 = intent.getStringExtra("eAdresseProprio");
    eNomEntreprise2 = intent.getStringExtra("eNomEntreprise");
    eAdresseEntreprise2 = intent.getStringExtra("eAdresseEntreprise");
    eJourVerif2 = intent.getStringExtra("eJourVerif");
    eMoisVerif2 = intent.getStringExtra("eMoisVerif");
    eAnneeVerif2 = intent.getStringExtra("eAnneeVerif");

}
于 2015-09-09T09:50:02.303 回答