0

私は Android の初心者で、オブジェクトが他のオブジェクトを含むアクティビティ間でオブジェクトを渡そうとしましたが、エラーが表示されます。

解決策?

serializable でオブジェクトを渡そうとします:

        lALL.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View v,
                    int position, long arg3) {
                System.out.println(position);
                Locataire l = new Locataire(getResources());
                l.setNom("test");
                l.setPrenom("test");
                Intent intent = new Intent(MainActivity.this, Etat_lieux.class);
                intent.putExtra("EDL", l);
                startActivity(intent);      
            }


        });

public class Locataire implements Serializable{

private String ref;
private String civilite;
private String nom;
private String prenom;
private Contact contact = new Contact();
private Adresse adresse = new Adresse();
private String DG;
private boolean IsGarantPresent;
private boolean IsColocation;

private Resources res;

public Locataire(Resources res)
{
    this.res = res;
}

連絡先、住所

public class Contact は Serializable を実装します{

protected String tel;
protected String mobile;
protected String fax;
protected String email;
protected String www;

そして、リソースは最初のアクティビティの Context getResources() です

4

2 に答える 2

0

エクストラでオブジェクトを渡したい場合は、オブジェクトに serializable を実装させ、そのすべてのサブオブジェクトに serializalbe を実装させ、 bundle.putSerializable(OBJECT) を使用する必要があります。

于 2015-08-30T22:16:50.347 に答える