Я не могу получить каждое Textviews, такое как «Отсутствует», «Настоящее время» и «Извините» внутри RecyclerView
, но TextView
имеет только один идентификатор. Как я могу получить все TextView
в RecyclerView
. Вот мой код в моем Activity
.
Это скриншот моего приложения.
Это мой MainActivity
.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_adapter);
final TextView dates,blocks;
blocks=findViewById(R.id.blocks);
dates=findViewById(R.id.dates);
database =FirebaseDatabase.getInstance();
submit=findViewById(R.id.sumbitBrn);
final String block = getIntent().getExtras().getString("Block");
final String date = getIntent().getExtras().getString("Date");
blocks.setText(block);
dates.setText(date);
swipeRefreshLayout = findViewById(R.id.refresh);
exampleList = new ArrayList<>();
values = new ArrayList<>();
myReff = FirebaseDatabase.getInstance().getReference("Section").child(block);
myReff.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot students:dataSnapshot.getChildren()){
Students students1 = students.getValue(Students.class);
exampleList.add(students1);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mAdapter = new ExampleAdapter(exampleList);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(MainAdapter.this);
mAdapter = new ExampleAdapter(exampleList);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
},4000);
}
});
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myReff =database.getReference("Date").child(dates.getText().toString()).child(blocks.getText().toString());
// I WILL INSERT HERE THE CODE FOR GETTING THE TEXTVIEWS INSIDE THE RECYCLER
Toast.makeText(MainAdapter.this,"SUCCESS!",Toast.LENGTH_LONG).show();
}
});
А это мой класс Адаптера. Я использую здесь группу Радио, чтобы установить текст в RecyclerView
, но я не знаю, чтобы получать каждые TextView
с.
private ArrayList<Students> mExampleList;
public static class ExampleViewHolder extends RecyclerView.ViewHolder{
public RadioGroup radioGroup;
public TextView mTextView1;
public TextView result;
public ExampleViewHolder(@NonNull View itemView) {
super(itemView);
radioGroup = itemView.findViewById(R.id.allRadioButton);
mTextView1 = itemView.findViewById(R.id.textView);
result = itemView.findViewById(R.id.res);
}
}
public ExampleAdapter(ArrayList<Students>exampleList) {
mExampleList = exampleList;
}
@NonNull
@Override
public ExampleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false);
ExampleViewHolder evh = new ExampleViewHolder(v);
return evh;
}
@Override
public void onBindViewHolder(@NonNull final ExampleViewHolder holder, int position) {
Students currentItem = mExampleList.get(position);
holder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.present:
holder.result.setText("Present");
break;
case R.id.absent:
holder.result.setText("Absent");
break;
case R.id.excuse:
holder.result.setText("Excuse");
break;
}
}
});
holder.mTextView1.setText(currentItem.getName());
}
@Override
public int getItemCount() {
return mExampleList.size();
}