can help me pls I am making an voting app
I have reached a stage when I want to choose someone who will increase the number of votes in the data base, and I do not know how to do it
I want a method. When the user clicks the name in the application, the count
increases in the data base from 1 to 2 and continues to increase whenever they click
I want read count from database and then increment it when click on button or textname in app
How to use Transaction in my code to do this depend on my database?
RecyclerView raees_RecyclerView;
private DatabaseReference databaseReference;
private ArrayList <Condidate> candidateArrayList;
private Context context;
FirebaseRecyclerAdapter<Condidate, RaeesRecyclerViewAdapter> adapter;
Button vote;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.raees__at7ad);
raees_RecyclerView = findViewById(R.id.raees_recyclerView);
LinearLayoutManager layoutManager =new LinearLayoutManager(this);
raees_RecyclerView.setLayoutManager(layoutManager);
raees_RecyclerView.setHasFixedSize(true);
vote = findViewById(R.id.voteBtn);
databaseReference = FirebaseDatabase.getInstance().getReference("المرشحون").child("رئيس اتحاد الطلبة");
candidateArrayList = new ArrayList <>();
loadDataFromfirebaseToRecyclerView();
}
private void loadDataFromfirebaseToRecyclerView() {
FirebaseRecyclerOptions <Condidate> options = new FirebaseRecyclerOptions.Builder<Condidate>()
.setQuery(databaseReference,Condidate.class)
.build();
FirebaseRecyclerAdapter<Condidate, RaeesRecyclerViewAdapter> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter <Condidate, RaeesRecyclerViewAdapter>(options) {
@Override
protected void onBindViewHolder(@NonNull final RaeesRecyclerViewAdapter viewHolder, int postion, @NonNull Condidate condidate) {
viewHolder.textView.setText(condidate.getName());
final Condidate clickItem= condidate;
viewHolder.setItemClickListener(new RecyclerViewInterface() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
// the method for make count increment in database here can help pls
}
}); }
@NonNull
@Override
public RaeesRecyclerViewAdapter onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.raees_card,parent,false);
return new RaeesRecyclerViewAdapter(view);
}
};
firebaseRecyclerAdapter.startListening();
raees_RecyclerView.setAdapter(firebaseRecyclerAdapter);
}
////////
public TextView textView;
private RecyclerViewInterface recyclerViewInterface;
public RaeesRecyclerViewAdapter(@NonNull View itemView) {
super(itemView);
textView=itemView.findViewById(R.id.raeesName);
itemView.setOnClickListener(this);
}
public void setItemClickListener(RecyclerViewInterface itemClickListener) {
this.recyclerViewInterface = itemClickListener;
}
@Override
public void onClick(View view) {
recyclerViewInterface.onClick(view,getAdapterPosition(),false);
}