0

I have created an activity which contains a button, a ViewPager and some fragments. When I click on the button a DialogActivity opens and connects to the web service using AsyncHttpClient and returns some strings which are pictures url, name, etc. to MainActivity. I want MainActivity to show the data in fragment specially the picture url (using Glide) but I can’t do this. I appreciate it if you help me

DialogActivity:

void parsAndShowBiography(String response) {
    try {
        Gson gson = new Gson();
        TheaudiodbBiography theaudiodbBiography = gson.fromJson(response, TheaudiodbBiography.class);
        Intent returnIntent = new Intent(DialogActivity.this, MainActivity.class);

        returnIntent.putExtra("artistThumb", theaudiodbBiography.getArtists()
                .get(0).getStrArtistThumb());
        returnIntent.putExtra("strArtist", theaudiodbBiography.getArtists()
                .get(0).getStrArtist());
        returnIntent.putExtra("artistFanart1", theaudiodbBiography.getArtists()
                .get(0).getStrArtistFanart());
        setResult(Activity.RESULT_OK, returnIntent);
        finish();

MainActivity :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 100 && resultCode == Activity.RESULT_OK) {

        ???????????????????????

    }

And this is the Fragment :

public class BiographyFragment extends Fragment {


static BiographyFragment instance;


public static BiographyFragment getInstance() {
    if (instance == null) {
        instance = new BiographyFragment();
    }


    return instance;
}


@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.bigraphy_fragment, container, false);
    return view;
}

I put some TextViews and ImageViews into Fragment xml file.

and if it helps this is the UX :

enter image description here

Marat
  • 6,142
  • 6
  • 39
  • 67
Hossein
  • 73
  • 1
  • 8

1 Answers1

0

Hi guys i solved the question with this code :

MainActivity :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 100 && resultCode == Activity.RESULT_OK) {

        View test=BiographyFragment.getInstance().getView();

        Glide.with(this).load(data.getStringExtra("artistFanart1")).into(
                            (ImageView)test.findViewById(R.id.artistFanart1));

    }
Hossein
  • 73
  • 1
  • 8