Skip to content Skip to sidebar Skip to footer

How To Delete Item From Arraylist On Another Activity & Update On Previous Activity?

I have an ArrayList I am sending item onItemClick On another activity from this:- list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterVi

Solution 1:

There is a good example here on how to communicate between activities. Basically you update the activity in the manifest and set android:launchMode="singleTask". Then you handle the onNewIntent methode for the called activity.

Solution 2:

Use StartActivityForResult(yourIntent,YOUR_REQUEST_CODE); and on the onActivityResult

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode)
    {
        case YOUR_REQUEST_CODE:
            if(resultCode == RESULT_OK)
                yourArrayList.remove(theItemClicked);
                yourListview.notifySetDataChanged();
            break;

        default:
            break;
    }

}

in the otherActivity simply set some Result in an INTENT and finish() that Activity on Delete Button's OnClick Event.

Post a Comment for "How To Delete Item From Arraylist On Another Activity & Update On Previous Activity?"