Я хочу обновить TextView
в адаптере (textViewNum) из действия SlotsActivity
, когда я нажал кнопку "btn"
Как я могу получить доступ к TextView
??
имейте в виду, что listItems
не пустой.
Вот мой Activity
код:
public class SlotsActivity extends AppCompatActivity{
private RecyclerView recyclerView;
private MyAdapter adapter;
private List<ListItem> listItems;
private Button btn;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slots);
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
listItems = new ArrayList<>();
....
btn=findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//i want to update the textview here
}
});
}
А вот и мой Adapter
:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<ListItem> listItems ;
private Context context;
public MyAdapter(List<ListItem> listItems, Context context) {
this.listItems = listItems;
this.context = context;
}
....
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
final ListItem listItem= listItems.get(position);
//**I want to update this textView**
holder.textViewNum.setText("N° slot : "+listItem.getNum()+"");
}
....
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView textViewNum;
public ViewHolder(View itemView) {
super(itemView);
textViewNum = itemView.findViewById(R.id.textViewNum);
}
}
}