Я разрабатываю приложение для викторины с помощью viewPager2. Я пролистываю страницы по клику. Как вы знаете, для перелистывания, нужно положение, чтобы вы могли получить его из адаптера. Проблема в том, что адаптер устанавливает две позиции одновременно одним щелчком мыши. Но когда я смахиваю страницы, касаясь страниц, адаптер устанавливает идеальную позицию, но когда я устанавливаю представление pager.setOncurrentItem (1), адаптер показывает две позиции одновременно , дайте мне знать, чтобы справиться с этой проблемой. Тем не мение
public V1105ad(List<cn2310st> list, Context context) {
this.list = list;
this.context = context;
ru = new Ut2310ru(context);
red10 = context.getResources().getColor(R.color.red);
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
System.out.println("view1:"+ viewType);
View view;
switch (viewType){
case INTRO:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.v2310_qz_type_1_new,parent,false);
return new quizHolder(view);
case MAIN:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.v2310_qz_type_2,parent,false);
return new resultHolder(view);
}
return null;
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
System.out.println("view:"+ holder + "position" + position);
sendData(position);
cn2310st obj = list.get(position);
final Drawable drR = context.getResources().getDrawable(R.drawable.ic_opt_back_red);
final Drawable drP = context.getResources().getDrawable(R.drawable.ic_opt_back);
final Typeface tf = Typeface.createFromAsset(holder.itemView.getContext().getAssets(),"fonts/roya.ttf");
if (obj != null){
qec = obj.getQec();
qzn = obj.getQzN();
switch (obj.getType()){
case INTRO :
((quizHolder)holder).qzttl.setText(obj.getEtx1());
((quizHolder)holder).opt1.setText(obj.getFtx1());
((quizHolder)holder).opt2.setText(obj.getEtx2());
((quizHolder)holder).opt3.setText(obj.getFtx2());
((quizHolder)holder).opt4.setText(obj.getEtx3());
((quizHolder)holder).r1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sdt.onOpt1(position);
sendData(position);
setSelected(holder,drR,drP,1);
}
});
((quizHolder)holder).r2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sdt.onOpt2(position);
sendData(position);
setSelected(holder,drR,drP,2);
}
});
((quizHolder)holder).r3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sdt.onOpt3(position);
sendData(position);
setSelected(holder,drR,drP,3);
}
});
((quizHolder)holder).r4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sdt.onOpt4(position);
sendData(position);
setSelected(holder,drR,drP,4);
}
});
break;
case MAIN :
Toast.makeText(context, "View2", Toast.LENGTH_SHORT).show();
new CountDownTimer(5000, 1000) {
@Override
public void onTick(long l) {
((resultHolder)holder).prRl.setVisibility(View.VISIBLE);
((resultHolder)holder).mainRl.setVisibility(View.INVISIBLE);
((resultHolder)holder).pr.setIndeterminate(true);
((resultHolder)holder).pr.setVisibility(View.VISIBLE);
((resultHolder)holder).pr.getIndeterminateDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
}
@Override
public void onFinish() {
((resultHolder)holder).prRl.setVisibility(View.GONE);
((resultHolder)holder).pr.setVisibility(View.GONE);
((resultHolder)holder).mainRl.setVisibility(View.VISIBLE);
((resultHolder)holder).t1.setTypeface(tf);
((resultHolder)holder).t2.setTypeface(tf);
((resultHolder)holder).t3.setTypeface(tf);
setPts(((resultHolder)holder).qn,((resultHolder)holder).ra,
((resultHolder)holder).wr,((resultHolder)holder).ti,
((resultHolder)holder).npr,((resultHolder)holder).rpr,
((resultHolder)holder).wpr);
((resultHolder)holder).ib1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sdt.onCheck(position);
}
});
}
}.start();
break;
}
}
}
@Override
public int getItemCount() {
if (list == null) {
return 0;
}
return list.size();
}
@Override
public int getItemViewType(int position) {
if (list !=null){
cn2310st st = list.get(position);
if (st!=null){
return st.getType();
}
}
return super.getItemViewType(position);
}
public class quizHolder extends RecyclerView.ViewHolder{
TextView qzttl,ttlTr,opt1,opt2,opt3,opt4,opt1lt,opt2lt,opt3lt,opt4lt,opt1tr,opt2tr,opt3tr,opt4tr;
RelativeLayout r1,r2,r3,r4;
ImageButton ib1,ib2,ib3,ib4;
quizHolder(@NonNull View itemView) {
super(itemView);
qzttl = itemView.findViewById(R.id.v2310_qz_qust_tx);
r1 = itemView.findViewById(R.id.v2310_qz_rl_opt1);
r2 = itemView.findViewById(R.id.v2310_qz_rl_opt2);
r3 = itemView.findViewById(R.id.v2310_qz_rl_opt3);
r4 = itemView.findViewById(R.id.v2310_qz_rl_opt4);
opt1 = itemView.findViewById(R.id.v2310_qz_opt_1_tx);
opt2 = itemView.findViewById(R.id.v2310_qz_opt_2_tx);
opt3 = itemView.findViewById(R.id.v2310_qz_opt_3_tx);
opt4 = itemView.findViewById(R.id.v2310_qz_opt_4_tx);
opt1lt = itemView.findViewById(R.id.v2310_qz_opt_1_lt);
opt2lt = itemView.findViewById(R.id.v2310_qz_opt_2_lt);
opt3lt = itemView.findViewById(R.id.v2310_qz_opt_3_lt);
opt4lt = itemView.findViewById(R.id.v2310_qz_opt_4_lt);
ib1 = itemView.findViewById(R.id.v2310_qz_opt_1);
ib2 = itemView.findViewById(R.id.v2310_qz_opt_2);
ib3 = itemView.findViewById(R.id.v2310_qz_opt_3);
ib4 = itemView.findViewById(R.id.v2310_qz_opt_4);
ttlTr = itemView.findViewById(R.id.v2310_qz_qust_tx_tr);
opt1tr = itemView.findViewById(R.id.v2310_qz_opt_1_tr);
opt2tr = itemView.findViewById(R.id.v2310_qz_opt_2_tr);
opt3tr = itemView.findViewById(R.id.v2310_qz_opt_3_tr);
opt4tr = itemView.findViewById(R.id.v2310_qz_opt_4_tr);
}
}
public class resultHolder extends RecyclerView.ViewHolder{
TextView ti,qn,ra,wr;
TextView t1,t2,t3;
ArcProgress npr,rpr,wpr;
RelativeLayout prRl,mainRl;
ProgressBar pr;
ImageButton ib1;
resultHolder(@NonNull View itemView) {
super(itemView);
ti = itemView.findViewById(R.id.v2310_qz_re_du);
t1 = itemView.findViewById(R.id.v2310_qz_re_qn_ttl);
t2 = itemView.findViewById(R.id.v2310_qz_re_right_ttl);
t3 = itemView.findViewById(R.id.v2310_qz_re_wrong_ttl);
qn = itemView.findViewById(R.id.v2310_qz_re_qn_dt);
ra = itemView.findViewById(R.id.v2310_qz_re_right_dt);
wr = itemView.findViewById(R.id.v2310_qz_re_wrong_dt);
npr = itemView.findViewById(R.id.v2310_qz_re_number_pr);
rpr = itemView.findViewById(R.id.v2310_qz_re_right_pr);
wpr = itemView.findViewById(R.id.v2310_qz_re_wrong_pr);
prRl= itemView.findViewById(R.id.v2310_qz_re_rel_progress);
mainRl= itemView.findViewById(R.id.v2310_qz_re_mainRl);
pr = itemView.findViewById(R.id.v2310_qz_re_progress);
ib1 = itemView.findViewById(R.id.v2310_qz_re_check);
}
}
2020-02-14 10:52:51.097 5744-5744/ir.x304.Vision I/System.out: posAd06:0
2020-02-14 10:52:54.807 5744-5744/ir.x304.Vision I/System.out: posAd06:1
2020-02-14 10:52:54.853 5744-5744/ir.x304.Vision I/System.out: posAd06:2
2020-02-14 10:53:01.319 5744-5744/ir.x304.Vision I/System.out: posAd06:3
2020-02-14 10:53:01.355 5744-5744/ir.x304.Vision I/System.out: posAd06:4
2020-02-14 10:53:31.062 5744-5744/ir.x304.Vision I/System.out: posAd06:0
2020-02-14 10:53:34.196 5744-5744/ir.x304.Vision I/System.out: posAd06:1
2020-02-14 10:53:34.228 5744-5744/ir.x304.Vision I/System.out: posAd06:2
2020-02-14 10:53:36.409 5744-5744/ir.x304.Vision I/System.out: posAd06:3
2020-02-14 10:53:36.447 5744-5744/ir.x304.Vision I/System.out: posAd06:4
2020-02-14 10:54:33.676 5908-5908/ir.x304.Vision I/System.out: posAd06:0
2020-02-14 10:54:35.148 5908-5908/ir.x304.Vision I/System.out: posAd06:1
2020-02-14 10:54:36.038 5908-5908/ir.x304.Vision I/System.out: posAd06:2
2020-02-14 10:54:36.887 5908-5908/ir.x304.Vision I/System.out: posAd06:3
2020-02-14 10:54:37.818 5908-5908/ir.x304.Vision I/System.out: posAd06:4
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/v2310_qz_rl_quiz"
android:orientation="vertical"
android:layout_marginBottom="@dimen/margin30"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/v2310_qz_rl_ttl"
android:orientation="vertical"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="@string/sampl_txt_eng"
android:id="@+id/v2310_qz_qust_tx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginRight="4dp"
android:gravity="start"
android:padding="9dp"
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
<TextView
android:text="@string/sampl_txt_prs"
android:id="@+id/v2310_qz_qust_tx_tr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginRight="4dp"
android:gravity="start"
android:visibility="gone"
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal" />
</LinearLayout>
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt1"
android:layout_below="@+id/v2310_qz_rl_ttl"
android:layout_marginTop="5dp"
android:background="@drawable/bg_overlay_j"
android:layout_marginStart="@dimen/margin10"
android:layout_marginEnd="@dimen/margin10"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt1_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/v2310_qz_opt_1"
android:text="@string/opt1"
android:background="@drawable/ic_opt_back"
android:padding="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/v2310_qz_opt_1_lt"
android:text="@string/letter_a"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_opt_rl_tx1"
android:layout_marginTop="3dp"
android:padding="4.5dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:layout_toRightOf="@+id/v2310_qz_rl_opt1_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt_1_tx"
android:text="@string/opt1"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:layout_below="@+id/v2310_qz_opt_rl_tx1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt1_tx_tr"
android:text="@string/show_trans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginRight="4dp"
android:gravity="start"
android:visibility="gone"
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt2"
android:layout_below="@+id/v2310_qz_rl_opt1"
android:background="@drawable/bg_overlay_j"
android:layout_marginTop="5dp"
android:layout_marginStart="@dimen/margin10"
android:layout_marginEnd="@dimen/margin10"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt2_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/v2310_qz_opt_2"
android:text="@string/opt1"
android:background="@drawable/ic_opt_back"
android:padding="20dp"
android:theme="@style/radioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/v2310_qz_opt_2_lt"
android:text="@string/letter_b"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_opt_rl_tx2"
android:layout_marginTop="4dp"
android:padding="4.5dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:layout_toRightOf="@+id/v2310_qz_rl_opt2_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt_2_tx"
android:text="@string/opt1"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:layout_below="@+id/v2310_qz_opt_rl_tx2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt2_tx_tr"
android:text="@string/show_trans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginRight="4dp"
android:gravity="start"
android:visibility="gone"
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt3"
android:layout_below="@+id/v2310_qz_rl_opt2"
android:background="@drawable/bg_overlay_j"
android:layout_marginTop="5dp"
android:layout_marginStart="@dimen/margin10"
android:layout_marginEnd="@dimen/margin10"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt3_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/v2310_qz_opt_3"
android:text="@string/opt1"
android:background="@drawable/ic_opt_back"
android:padding="20dp"
android:theme="@style/radioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/v2310_qz_opt_3_lt"
android:text="@string/letter_c"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_opt_rl_tx3"
android:layout_marginTop="4dp"
android:padding="4.5dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:layout_toRightOf="@+id/v2310_qz_rl_opt3_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt_3_tx"
android:text="@string/opt1"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:layout_below="@+id/v2310_qz_opt_rl_tx3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt3_tx_tr"
android:text="@string/show_trans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginRight="4dp"
android:gravity="start"
android:visibility="gone"
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt4"
android:layout_below="@+id/v2310_qz_rl_opt3"
android:background="@drawable/bg_overlay_j"
android:layout_marginTop="5dp"
android:layout_marginStart="@dimen/margin10"
android:layout_marginEnd="@dimen/margin10"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/v2310_qz_rl_opt4_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/v2310_qz_opt_4"
android:text="@string/opt1"
android:background="@drawable/ic_opt_back"
android:padding="20dp"
android:theme="@style/radioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/v2310_qz_opt_4_lt"
android:text="@string/letter_d"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/v2310_qz_opt_rl_tx4"
android:layout_marginTop="4dp"
android:padding="4.5dp"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:layout_toRightOf="@+id/v2310_qz_rl_opt4_ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt_4_tx"
android:text="@string/opt1"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="normal" />
</RelativeLayout>
<RelativeLayout
android:layout_below="@+id/v2310_qz_opt_rl_tx4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/v2310_qz_opt4_tx_tr"
android:text="@string/show_trans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginRight="4dp"
android:gravity="start"
android:visibility="gone"
android:fontFamily="sans-serif"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>