我创建了一个应用程序,它可以显示手机存储器中的视频。我想创建一个功能,当用户点击其中一个视频时,如果点击的视频长度超过5分钟或少于2分钟,就会弹出祝酒词。如何在recyclerview适配器中实现这一点。下面是我的recyclerview适配器。
recyclerview适配器
public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.ViewHolder> {
private Context context;
private ArrayList<VideoModel> videoModels;
public VideoAdapter(Context context, ArrayList<VideoModel> videoModels) {
this.context = context;
this.videoModels = videoModels;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.lists_of_videos, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
final VideoModel vidModel = videoModels.get(position);
Glide.with(context).load(vidModel.getData()).into(holder.video_thumb);
holder.duration.setText(vidModel.getDuration());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (vidModel.getData() != null){
Intent intent = new Intent(context, SelectedVideoActivity.class);
intent.putExtra("videoURL", vidModel.getId());
context.startActivity(intent);
}else {
Toast.makeText(context, "Invalid video", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public int getItemCount() {
return videoModels.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
ImageView video_thumb;
TextView duration;
public ViewHolder(@NonNull View itemView) {
super(itemView);
video_thumb = itemView.findViewById(R.id.video_thumb);
duration = itemView.findViewById(R.id.duration);
}
}
视频模型类
public class VideoModel{
long id;
Uri data;
String duration;
public VideoModel(long id, Uri data, String duration){
this.id = id;
this.data = data;
this.duration = duration;
}
public long getId(){
return id;
}
public void setId(long id){
this.id= id;
}
public Uri getData(){
return data;
}
public void setData(Uri data){
this.data= data;
}
public String getDuration(){
return duration:
}
public void setDuration(String duration){
this.duration=duration;
}
}
2条答案
按热度按时间bogh5gae1#
假设以毫秒(msec)为单位保存持续时间
然后在列表项中按下面的方式执行
onClick
回拨sulc1iza2#
首先,每60000等于1分钟。在onclick中: