我有一個ArrayList具有Person類型的對象。人員類別具有字段名稱,地址1,地址2,城市,州,郵編和國家。我希望能夠編輯特定的人員,然後更新這些更改,以便顯示人員的ListAdapter顯示更新的數據。這ListView控件包含在RecipientActivity(活動A)如何捕獲在ListView的CustomListAdapter類中的意圖的結果android
在自定義適配器我使用TextView的的onClick事件的意圖開始活動RecipientAddressActivity(活動B):
holder.txtRecName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent rec_Intent = new Intent(context,
RecipientAddressActivity.class);
rec_Intent.putExtra("Current_Recipient",
recipientArray.get(index));
rec_Intent.putExtra("RecipientIndex",index);
context.startActivity(rec_Intent);
}
});
在活動BI得到Current_Recipient在的onCreate指數()事件是這樣的:
current_rec = (Person) getIntent().getSerializableExtra(
"Current_Recipient");
Recipient_Index = getIntent().getIntExtra("RecipientIndex", 151);
在同一活動中,我有一個按鈕「保存」,並在它的OnClick我創建了一個Person對象,它可以是一個新的人或老人正在編輯。
按鈕保存的onClick()事件
{
Intent Recipient_info = new Intent();
Person recipient = new Person(edt_rec_name.getText().toString(),
edt_rec_addr1.getText().toString(),edt_rec_addr2.getText().toString(),
edt_rec_city.getText().toString(), edt_rec_state.getText().toString(),
edt_rec_pcode.getText().toString(), edt_rec_country.getText().toString());
Recipient_info.putExtra("Person", recipient);
Recipient_info.putExtra("RecipientIndex", Recipient_Index);
setResult(RESULT_OK, Recipient_info);
finish();
}
的問題是有開始活動B.我不知道在哪裏或如何捕捉到結果時Actvity B被使用ListView的適配器開始的2種方式。
請儘快幫助我。請讓我知道是否需要更多的代碼或解釋。
謝謝。
貴Person類實現parcelable? – Raghunandan
@Raghunandan不,它實現了Serializable。對於android parcelable, – user2688158
比序列化更好。 googe搜索示例並按照教程 – Raghunandan