Question

I have an ArrayList which has objects of type Person. Person class has fields name, address1, address2, city, state, postcode and country. I want to be able to edit a particular person and then update the changes such that the ListAdapter which displays the Persons shows updated data. This ListView is contained in RecipientActivity (Activity A)

In the custom Adapter I start the Activity RecipientAddressActivity (Activity B) using an intent in the TextView's onClick event:

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

        }
    }); 

In the Activity B I get the Current_Recipient and the index in onCreate() event like this:

current_rec = (Person) getIntent().getSerializableExtra(
            "Current_Recipient");
Recipient_Index = getIntent().getIntExtra("RecipientIndex", 151);

In the same activity, I have a button "Save" and on its Onclick I create a Person object which can be either a new Person or an old person being edited.

Button Save's onClick() event

{
  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();
}

The problem is there are 2 ways of starting Activity B. I don't know where or how to catch the result when Actvity B is started using ListView's Adapter.

Please help me asap. Kindly let me know if some more code or explanation is required.

Thanks.

Was it helpful?

Solution

I have noticed that in your code:

you are not starting activity as activityForResult.

check that and try now! if you still face this problem than here are some links, that will be useful in your problem:

calling onActivityResult from CustomArray adapter

onActivityResult in not called in the class extended from ArrayAdapter

How to add item in Custom listView in onActivityResult method?

How to Call onActivityResult in adapter listview?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top