我想创建一个自定义列表视图,它看起来像facebook时间线。为此,我创建了一个自定义列表视图。自定义列表视图将在Home片段中膨胀,该片段将是MainActivity的一部分。
我创建了一个包含文本和图像的布局,它工作正常。现在我想在我的Feed中添加一个youtube播放器。
每当我尝试将YouTubePlayerView或YouTubeFragment添加到自定义列表视图的布局时,都会出现错误,“错误导致类com.google.android.youtube.player.YouTubePlayerView”
我的问题是可以吗?
这是我的CustomFeedsList.java类:
public class FeedsCustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] UN;
private final Integer[] imageId;
private String[] VideoID;
public FeedsCustomList(Activity context,
String[] UN, Integer[] imageId, String[] VideoID) {
super(context, R.layout.video_list_items, UN);
this.context = context;
this.UN = UN;
this.imageId = imageId;
this.VideoID = VideoID;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.feeds_layout, null, true);
LoaderMethod(rowView, position);
return rowView;
}
public void LoaderMethod(final View rowView, final int position){
ImageView PROFILE = (ImageView) rowView.findViewById(R.id.feeds_profile_picture_IV);
TextView USERNAME = (TextView) rowView.findViewById(R.id.feeds_username_TV);
TextView TIMEV = (TextView) rowView.findViewById(R.id.feeds_postTime_TV);
TextView STATUS = (TextView) rowView.findViewById(R.id.status_TV);
ImageView IMAGE = (ImageView) rowView.findViewById(R.id.feeds_image_IV);
LinearLayout linearLayout = (LinearLayout) rowView.findViewById(R.id.linearLayout_YT);
// YouTubePlayerView youTubeView = (YouTubePlayerView) rowView.findViewById(R.id.youtube_view);
USERNAME.setText(UN[position]);
PROFILE.setImageResource(imageId[position]);
TIMEV.setText(UN[position]);
STATUS.setText(UN[position]);
if (imageId[position] != 0) {
IMAGE.setImageResource(imageId[position]);
} else IMAGE.setVisibility(View.GONE);
if (!VideoID[position].equals("null")) {
}
else linearLayout.setVisibility(View.GONE);
}
}
这是我的Home.java片段类:
public class Home extends Fragment {
public Home() {
// Required empty public constructor
}
final String[] names ={"mic","moneyd","nav_head","thumbnail","status","image"};
Integer[] images = {R.drawable.mic,
R.drawable.moneyd,
R.drawable.nav_head,
R.drawable.thumbnail,
0,
R.drawable.ic_home_black_24dp};
String[] VideoID = {"null","null","null","null","P3mAtvs5Elc","null"};
ImageView PROFILE;
TextView USERNAME;
TextView TIME;
TextView STATUS;
ImageView IMAGE;
VideoView VIDEO;
ListView feedsList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home, container, false);
feedsList = (ListView) view.findViewById(R.id.feedList);
FeedsCustomList adapter = new
FeedsCustomList(getActivity(), names, images,VideoID);
feedsList.setAdapter(adapter);
// VIDEO = (VideoView) view.findViewById(R.id.feeds_video_VV);
// VIDEO.setVisibility(View.GONE);
return view;
}
}
编辑:这是logcat:
10-16 17:38:05.621 13311-13322/? E/art: Failed sending reply to debugger: Broken pipe
10-16 17:38:07.061 13311-13311/svtinida.shreyans.com.smartschoolindia E/Process: android_os_Process_getProcessNameByPid pid is 13311
10-16 17:38:07.061 13311-13311/svtinida.shreyans.com.smartschoolindia E/Process: android_os_Process_getProcessNameByPid value is martschoolindia
10-16 17:38:08.371 13311-13311/svtinida.shreyans.com.smartschoolindia E/AndroidRuntime: FATAL EXCEPTION: main
Process: svtinida.shreyans.com.smartschoolindia, PID: 13311
android.view.InflateException: Binary XML file line #68: Error inflating class com.google.android.youtube.player.YouTubePlayerView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at svtinida.shreyans.com.smartschoolindia.FeedsCustomList.getView(FeedsCustomList.java:54)
at android.widget.AbsListView.obtainView(AbsListView.java:2391)
at android.widget.ListView.makeAndAddView(ListView.java:1893)
at android.widget.ListView.fillDown(ListView.java:708)
at android.widget.ListView.fillFromTop(ListView.java:769)
at android.widget.ListView.layoutChildren(ListView.java:1687)
at android.widget.AbsListView.onLayout(AbsListView.java:2195)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1692)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1468)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1167)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:852)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:871)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15697)
at android.view.ViewGroup.layout(ViewGroup.java:5064)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2260)
at android.view.ViewRootImpl.perform