0
我想在自定義尋呼機適配器中啓動Fragment。但是,我不知道如何讓getSupportFragmentManager()
開始交易。如何從PagerAdapter開始片段
非常感謝您在這件事上的時間和協助。
這是尋呼機我的代碼,自定義適配器:
public static class SlideShowAdapter extends PagerAdapter {
private ArrayList<Movie> popularMovieList;
private LayoutInflater inflater;
private Context context;
public SlideShowAdapter(Context context, ArrayList<Movie> popularMovieList) {
this.context = context;
this.popularMovieList =popularMovieList;
inflater = LayoutInflater.from(context);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount()
{
return popularMovieList.size();
}
@Override
public Object instantiateItem(ViewGroup view, final int position) {
View myImageLayout = inflater.inflate(R.layout.slide, view, false);
ImageView myImage = (ImageView) myImageLayout
.findViewById(R.id.slideShowImg);
Picasso.with(context).load(popularMovieList.get(position).getImage()).into(myImage);
view.addView(myImageLayout, 0);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MovieFragment movieFragment = MovieFragment
.newInstance(popularMovieList.get(position),popularMovieList.get(position).getGenre());
/***These code below does not work*/
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.fragArea,movieFragment)
.addToBackStack(null)
.commit();
}
});
return myImageLayout;
}
我試過第二種方法,它是正確的。但是,當我點擊該項目時,它沒有出現碎片 – DonDave