How to return to Activity and execute a method?

Asked

Viewed 77 times

1

have the Activity Profile.class and it displays my photos, when clicking on it, opens a fragmentDialog displaying the photo in slideshow... but when deleting the photo, need q back to my profile and update my photos, running photos(myID);

How to do this, if possible?!

Slideshowdialogfragment.class

private void delete_photo(final String idPhoto){
        pDialog.setMessage(getResources().getText(R.string.wait));
        showDialog();
        String tag = "deletePhoto";
        pDialog.setMessage(getResources().getText(R.string.wait));
        showDialog();
        StringRequest req = new StringRequest(Request.Method.POST,
                Config.DEL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                hideDialog();
                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");
                    if (!error) {
                        new Alert().MessageSuccess(getActivity(), view,
                                getText(R.string.delete_photo_success).toString());
                        // Voltar para meu Perfil.class e executar fotos(myID);


                    } else {
                        new Alert().MessageError(getActivity(), view,
                                getText(R.string.delete_photo_error).toString());
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                new Alert().MessageError(getActivity(), view,
                        getText(R.string.error_connection).toString());
                hideDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("me", myID);
                params.put("id", idPhoto);
                params.put("token", code);
                return params;
            }
        };
        CustomApplication.getInstance().addToRequestQueue(req, tag);
    }

1 answer

3


Step by step:

1 - Create an interface and put a method inside it void resposta();
2 - Have Activity implement this interface and program within the implemented list update method.
3 - Inside the fragment, declare an interface type variable.
4 - When creating the fragment, send this(to Activity) and insert this this into the interface variable that is in the fragment.
5 - When you finish the photo deletion method from the fragment (or in the last line of the deletion method), call interface.();

This final command will call the method resposta(); da Activity(pq in the interface will contain the this value of Activity).

  • I didn’t understand step 3 and 4... I created the Photosrefreshmyprofile interface and in the Profile I used Photosrefreshmyprofile. Also in Profile I created the method @Override public void reply() { photos(myID); } this right here ?

  • I did, thank you very much :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.