我有一个水平回收视图与一个缩略图和文本。在单击缩略图时,应播放相应的视频。我能够显示图像和文本,现在我被塞进了进一步的发挥videos.Any帮助将不胜感激。
主活性
public class MainActivity extends AppCompatActivity {
private RecyclerView horizontal_recycler_view;
private ArrayList<String> horizontalList;
private HorizontalAdapter horizontalAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
horizontal_recycler_view = (RecyclerView) findViewById(R.id.horizontal_recycler_view);
horizontalList = new ArrayList<>();
horizontalList.add("horizontal 1");
horizontalList.add("horizontal 2");
horizontalList.add("horizontal 3");
horizontalList.add("horizontal 4");
horizontalList.add("horizontal 5");
horizontalAdapter = new HorizontalAdapter(this, horizontalList);
LinearLayoutManager horizontalLayoutManager
= new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
horizontal_recycler_view.setLayoutManager(horizontalLayoutManager);
horizontal_recycler_view.setAdapter(horizontalAdapter);
}}
适配器
public class HorizontalAdapter extends RecyclerView.Adapter<HorizontalAdapter.MyViewHolder> {
private List<String> horizontalList;
Context ctxt;
public HorizontalAdapter(Context context, List<String> horizontalList) {
this.ctxt = context;
this.horizontalList = horizontalList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.horizontal_item_view, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
holder.txtView.setText(horizontalList.get(position));
holder.imgView.setImageResource(R.drawable.thumbnail);
holder.txtView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ctxt, holder.txtView.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return horizontalList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView txtView;
public ImageView imgView;
public MyViewHolder(View view) {
super(view);
imgView = (ImageView) view.findViewById(R.id.thumbnail);
txtView = (TextView) view.findViewById(R.id.video_title);
}
}}
发布于 2017-10-03 12:41:55
Main Activity in --->>
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
recyclerView.setAdapter(new Top_ServiceAdapter());
---->Adapter in you horizontal_item_view.xml layout in
linearlayout in image or text with orientation vertical .... so done this problem发布于 2017-10-03 12:44:45
首先,您应该创建一个包含"title“、"videoUrl”、"thumbnail_url“的类项。
然后,您的横向列表将是
private List<Item> horizontalList;然后,在您的viewHolder上,您将获得videoUrl并打开新的活动,其目的是将视频url包含在其包中。
Intent intent = new Intent(ctxt, VideoActivity.class);
intent.putExtra("VIDEO_URL", item.videoUrl);
startActivity(intent);然后,在您的VideoActivity上,您应该实现一个videoPlayer库来使用检索到的videoUrl显示视频
Intent intent = getIntent();
String videoUrl = intent.getStringExtra("VIDEO_URL");https://stackoverflow.com/questions/46544642
复制相似问题