Android 比赛注册应用程序中的倒计时
我正在制作一个锦标赛应用程序,组织者在其中设置锦标赛,玩家可以在图尔南注册。我想在一个有recyclerview的片段中设置倒计时。但当我声明CountDownTimer变量并在方法中使用它时,它会给我错误提示:Android 比赛注册应用程序中的倒计时,android,android-fragments,android-recyclerview,countdowntimer,android-viewholder,Android,Android Fragments,Android Recyclerview,Countdowntimer,Android Viewholder,我正在制作一个锦标赛应用程序,组织者在其中设置锦标赛,玩家可以在图尔南注册。我想在一个有recyclerview的片段中设置倒计时。但当我声明CountDownTimer变量并在方法中使用它时,它会给我错误提示: incompatible types: no unique maximal instance exists for type variable T with upper bounds CountDownTimer,View countDownTimer = itemView.f
incompatible types: no unique maximal instance exists for type variable T with upper bounds CountDownTimer,View
countDownTimer = itemView.findViewById(R.id.live_time);
^
其中T是一个类型变量:
T扩展方法findViewById(int)中声明的视图
请帮帮我
回收器取景器:
public class MyViewholder extends RecyclerView.ViewHolder {
TextView TypeTextView,ParticipantsTextView;
ImageView GameImageView;
CountDownTimer countDownTimer;
public MyViewholder(@NonNull View itemView) {
super(itemView);
TypeTextView = itemView.findViewById(R.id.live_tournament_type);
ParticipantsTextView = itemView.findViewById(R.id.live_tournament_participants);
GameImageView = itemView.findViewById(R.id.live_image_view);
countDownTimer = itemView.findViewById(R.id.live_time);
}
}
视图持有者布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="@+id/live_image_view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:src="@drawable/live_dota_wall" />
<TextView
android:id="@+id/live_tournament_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/live_image_view"
android:layout_marginBottom="60dp"
android:text="Tournament Type: "
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/live_tournament_participants"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/live_image_view"
android:layout_marginBottom="10dp"
android:text="Tournament \nParticipants: "
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/live_open_till"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/live_image_view"
android:layout_alignBottom="@id/live_image_view"
android:layout_marginBottom="40dp"
android:text="Resgisteration \nOpen Till:"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/live_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/live_image_view"
android:layout_alignBottom="@id/live_image_view"
android:layout_marginRight="40dp"
android:layout_marginBottom="10dp"
android:text="TIME"
android:textColor="#FFFFFF"
android:textSize="20sp" />
代码中的问题是,您试图将
文本视图
对象保存在倒计时
对象中,这在编程上是错误的。只有当倒计时计时器是TextView的子类时,这才是正确的
要使用倒计时,android文档中非常详细地提到了语法
你可以看看这个
https://developer.android.com/reference/android/os/CountDownTimer