그래서 세 개의 탭이 있으며 그 중 두 개의 탭에 개조 호출을해야합니다.세 개의 탭이있는 탭 레이아웃을 사용하는 경우 어떤 방법으로 추가 장착 호출을해야합니까?
나는 onCreateView 메서드에서 retrofit 호출이있는 메서드를 호출 해 보았습니다. onResponse 메서드에서받은 URL을 통해 이미지로드를 시도했습니다. 하지만 내 응용 프로그램을 디버깅 할 때 onResponse가 호출되기 전에도 onCreateView가 뷰를 반환합니다.
어떤 방법으로 단편에 추가 호출을해야합니까?
public class Tab3Fragment extends Fragment {
private ImageView trailer_thumbnail;
private static final String preImgUrl = "http://img.youtube.com/vi/";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab3_fragment, container, false);
trailer_thumbnail = (ImageView) rootView.findViewById(R.id.trailer_thumbnail);
updateTrailer();
/*if(DetailsActivity.movieTrailerList.size() != 0)
Picasso.with(getContext()).load(preImgUrl + DetailsActivity.movieTrailerList.get(0).getKey() + "/default.jpg").
placeholder(R.mipmap.ic_launcher).
error(R.mipmap.ic_launcher).
into(trailer_thumbnail);*/
return rootView;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
private void updateTrailer(){
final ProgressDialog mProgressDialog = new ProgressDialog(getContext());
mProgressDialog.setIndeterminate(true);
mProgressDialog.setMessage("Loading...");
mProgressDialog.show();
Retrofit retrofit = new Retrofit.Builder().
baseUrl(MainActivity.baseUrl).
addConverterFactory(GsonConverterFactory.create()).
build();
final RequestInterface requestInterface = retrofit.create(RequestInterface.class);
Call<MovieTrailerResponse> call1 = requestInterface.getMovieTrailers(list.get(index).getId(), MainActivity.apiKEy);
call1.enqueue(new Callback<MovieTrailerResponse>() {
@Override
public void onResponse(Call<MovieTrailerResponse> call, Response<MovieTrailerResponse> response) {
if (mProgressDialog.isShowing())
mProgressDialog.dismiss();
List<MovieTrailer> movieTrailerList = response.body().getResults();
Log.i("trailer", preImgUrl + movieTrailerList.get(0).getKey() + "/default.jpg");
if (movieTrailerList.get(0).getSite() == "YouTube")
Picasso.with(getActivity()).load(preImgUrl + movieTrailerList.get(0).getKey() + "/default.jpg").
into(trailer_thumbnail);
}
@Override
public void onFailure(Call<MovieTrailerResponse> call, Throwable t) {
}
});
}
이것은 내가 응용 프로그램을 디버깅하고 때, onCreateView
심지어 트레일러 탭이 선택되고 있으며, API 호출은 데이터를 수신하기 전에 뷰가 반환되기 전에 호출되고 내 tab3에 조각 클래스. 그래서 나는 progressdialog와 함께 이미지를로드 할 수 없습니다. 사실 tab2를 선택하면 진행 대화 상자가 표시됩니다.
내 요구 사항에 따라 다릅니다.하지만 내 앱을 디버깅 할 때 onResponse가 호출되기 전에도 onCreateView가 뷰를 반환합니다. ' 그게 뭐가 문제 야? 너 정확히 뭘 하려구? – OBX
api 호출에서받은 picasso URL을 사용하여 내 imageview를로드하려고하므로 onCreateView가 내 이미지 뷰가로드되기 전에 뷰를 반환합니다. – potter13