Posts

Showing posts with the label android-recyclerview

What is the best trick to handle null values in Recycler-view onBindViewHolder?

What is the best trick to handle null values in Recycler-view onBindViewHolder? I handled many exception regarding null/index-outof-bound etc. But i am thinking that this is not right way to go like if/else , so anyone can guide me How to handle all null condition in onBindViewHolder? @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof CustDtlsHolder) { // >i am getting here lots of null values below if(position < arr_custdetails.size()) { String dateInString = arr_custdetails.get(position).getLastVisitDate(); Date date = null; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); try { date = formatter.parse(dateInString); SimpleDateFormat formatter2 = new SimpleDateFormat("dd/MMM/yyyy...