gpt4 book ai didi

java - 在 RecyclerView 中访问同一行中的所有元素

转载 作者:行者123 更新时间:2023-12-01 09:13:54 29 4
gpt4 key购买 nike

RecyclerView

我有一个回收 View ,如图所示,每行包含两个按钮

我已将 onClickListener 添加到 Button-A

如果用户单击按钮 A,是否可以访问同一行中的按钮 B在同一行?

class BooksHolder extends RecyclerView.ViewHolder{

public BooksHolder(View itemView) {
super(itemView);
Download=(Button)itemView.findViewById(R.id.download);
pb=(ProgressBar)itemView.findViewById(R.id.progressBar1) ;
Download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Download.setVisibility(Button.INVISIBLE);
new DelayTask().execute();

}
});
}
}

public class DelayTask extends AsyncTask<Void, Integer, String> {
int count=0 ;
@Override
protected void onPreExecute() {
pb.setVisibility(ProgressBar.VISIBLE);

}

@Override
protected String doInBackground(Void... params) {
while (count < 5) {
SystemClock.sleep(1000);
count++;
publishProgress(count * 20);
}
return "Complete";
}

@Override
protected void onProgressUpdate(Integer... values) {
pb.setProgress(values[0]);

}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
SystemClock.sleep(100);
pb.setVisibility(ProgressBar.INVISIBLE);
Download.setVisibility(Button.VISIBLE);
Download.setEnabled(false);
}
}

下载按钮已在适配器中声明pb是ProgressBar已经在Adapter中声明了

最佳答案

您可以在 viewHolder 中实现 onClickListener

示例

static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
Button button1;
Button button2;

public MyViewHolder(View itemView) {
super(itemView);
button1 = (Button) itemView.findViewById(R.id.button1);
button2 = (Button) itemView.findViewById(R.id.button2);

button1.setOnClickListener(this);
button2.setOnClickListener(this);
}

@Override
public void onClick(View view) {
if (view == button1) {
// your action here
} else if (view == button2) {
// your action here
}
}
}

关于java - 在 RecyclerView 中访问同一行中的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40721419/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com