Click here to Skip to main content
15,894,539 members

Comments by Kumar Harsh 2021 (Top 4 by date)

Kumar Harsh 2021 26-Sep-21 9:44am View    
What is ItemInfo here can you please tell?
Kumar Harsh 2021 17-Sep-21 10:33am View    
This is my adapter class...please let me know if here i have to insert the code.. I have user countdown timer in the onebindholder method....


public class MyAdapter extends RecyclerView.Adapter<myadapter.holder> {
// creating variables for our ArrayList and context
private ArrayList<userdet> UserArrayList;
private HomeFragment context;
String timey ;


// creating constructor for our adapter class
public MyAdapter(ArrayList<userdet> UserArrayList, HomeFragment context) {
this.UserArrayList = UserArrayList;
this.context = context;
}

@NonNull
@Override
public MyAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new Holder(LayoutInflater.from(context.getActivity()).inflate(R.layout.onerowforrecview, parent, false));
}

@Override
public void onBindViewHolder(@NonNull Holder holder, int position) {
// setting data to our text views from our modal class.
UserDet userDet = UserArrayList.get(position);

holder.ques_name_h.setText(userDet.getCategoryName());
}





long timer = userDet.getCategoryTime().toDate().getTime();
Date today = new Date();

final long currentTime = System.currentTimeMillis();

long expiryTime = timer - currentTime;


new CountDownTimer(expiryTime, 1000) {
public void onTick(long millisUntilFinished) {
long seconds = millisUntilFinished / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;

timey = days+"d, " +hours % 24 + "h left";

holder.ques_time_h.setText(timey);
}

public void onFinish() {
holder.ques_amount_h.setButtonColor(R.color.teal_200);
holder.itemView.setEnabled(false); //makig disclick
holder.ques_time_h.setText("Time up!");
holder.ques_amount_h.setEnabled(false); //btn disabled


Handler handler = new Handler();
Runnable run= new Runnable() {
@Override
public void run() {
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
params.height = 0;
params.width=0;

holder.itemView.setLayoutParams(params);
handler.postDelayed(this,5000);
}
};
handler.post(run);




}
}.start();



holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intent= new Intent(context.getActivity(),TournamentDetails.class);
context.startActivity(intent);
}

});


}

@Override
public int getItemCount() {
// retu
Kumar Harsh 2021 17-Sep-21 10:06am View    
Sir please Check this code..and let me know where to add the above 3 line which you told....


coursesArrayList = new ArrayList<>();
rcv.setHasFixedSize(false);
rcv.setItemViewCacheSize(4);
rcv.setLayoutManager(new LinearLayoutManager(getContext()));

// adding our array list to our recycler view adapter class.
myAdapter = new MyAdapter(coursesArrayList, this);

// setting adapter to our recycler view.
rcv.setAdapter(myAdapter);



// below line is use to get the data from Firebase Firestore.
// previously we were saving data on a reference of Courses
// now we will be getting the data from the same reference.
db.collection("categories").orderBy("categoryTime", Query.Direction.ASCENDING)
.addSnapshotListener(new EventListener<querysnapshot>() {
@Override
public void onEvent(@Nullable @org.jetbrains.annotations.Nullable QuerySnapshot value, @Nullable @org.jetbrains.annotations.Nullable FirebaseFirestoreException error) {
if (!value.isEmpty()) {
shimmerFrameLayout.stopShimmer();
shimmerFrameLayout.setVisibility(View.INVISIBLE);

List<documentsnapshot> list = value.getDocuments();

coursesArrayList.clear(); //clear old refresh new
for (DocumentSnapshot d : list) {
// after getting this list we are passing
// that list to our object class.
UserDet ud = d.toObject(UserDet.class);

assert ud != null;
ud.setCategoryID(d.getId());

// and we will pass this object class
// inside our arraylist which we have
// created for recycler view.
coursesArrayList.add(ud);

}
myAdapter.notifyDataSetChanged();
} else {
// if the snapshot is empty we are displaying a toast message.
Toast.makeText(getActivity() , "No data found in Database", Toast.LENGTH_SHORT).show();
}
}
});
Kumar Harsh 2021 17-Sep-21 8:49am View    
Can you please elabourate a bit..add() is giving me an infinte recylerview