如何在扩展getChildFragmentManager()
的自定义适配器中使用方法ArrayAdapter<>
?
如果你需要看到我的代码,请点击这里:
MyAdapter.java:
public class MyAdapter extends ArrayAdapter<Content> {
Context context;
List<Content> myList;
public static final String pattern = "(?<=watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*";
public MyAdapter(Context context, int resource, List<Content> objects) {
super(context, resource, objects);
this.context = context;
this.myList = objects;
}
@Override
public int getCount() {
if (myList != null)
return myList.size();
return 0;
}
@Override
public Content getItem(int position) {
if (myList != null)
return myList.get(position);
return null;
}
@Override
public long getItemId(int position) {
if (myList != null)
return myList.get(position).hashCode();
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
holder.contId = (TextView) convertView.findViewById(R.id.content_id);
holder.contType = (TextView) convertView.findViewById(R.id.type);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.txtTeaser = (TextView) convertView.findViewById(R.id.teaser);
holder.imageView = (ImageView) convertView.findViewById(R.id.cover_photo);
holder.youTubeVideo = (FrameLayout) convertView.findViewById(R.id.youTube_frame);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
Content content = getItem(position);
holder.contId.setText(content.getId());
holder.contType.setText(content.getType());
holder.txtTitle.setText(content.getTitle());
holder.txtTeaser.setText(content.getTeaser());
Picasso.with(context).load(Uri.parse(content.getImageUrl())).into(holder.imageView);
if(content.getCoverVideo() != null && !content.getCoverVideo().equals("")){
String cover_video = content.getCoverVideo();
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(cover_video);
if(matcher.find()){
cover_video = matcher.group();
}
Bundle youTubeBundle = new Bundle();
youTubeBundle.putString("link", cover_video);
FragmentManager manager = getChildFragmentManager(); // <------ Can't resolve method
FragmentTransaction transaction = manager.beginTransaction();
ArticleYouTubeFragment youtubeFragment = new ArticleYouTubeFragment();
youtubeFragment.setArguments(youTubeBundle);
transaction.replace(R.id.list_youTube_frame, youtubeFragment);
transaction.commit();
}
return convertView;
}
private class Holder {
TextView contId;
TextView contType;
TextView txtTitle;
TextView txtTeaser;
ImageView imageView;
FrameLayout youTubeVideo;
}
}
提前致谢。