Background: I have a Picasso Statement in my java file, which reads a JSON and then formats that data to the screen. The Issue: Once my JSON has been re
Use this for old library :-
(implementation 'com.squareup.picasso:picasso:2.5.2')
Picasso.with(this).load(iconUrl).into(Tab1Fragment.weatherIcon);
instead of : For new library
(implementation 'com.squareup.picasso:picasso:2.71828')
Picasso.get().load(iconUrl).into(Tab1Fragment.weatherIcon);
I think you need to set load image from Picasso to ImageView inside Tab1Fragment
.
And need to make sure Picasso load to ImageView
after fragment already run onCreateView
to inflate view and ImageView
I made an example
In activity
PlaceholderFragment placeholderFragment = (PlaceholderFragment) mSectionsPagerAdapter.getItem(0);
placeholderFragment.setIcon("http://openweathermap.org/img/w/01d.png");
Fragment
public class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
private ImageView imageView;
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
this.imageView = rootView.findViewById(R.id.imageView);
return rootView;
}
public void setIcon(String url) {
if (imageView == null) {
throw new RuntimeException("ImageView null, please make sure this setIcon function run after onCreateView");
}
Picasso.get().load(url).into(imageView);
}
}