Reputation: 9
I want to set a counter within the grey shaded Textview for each BDE. Clicking on the name of the BDE how many members are working under that particular BDE, is going to visible. But I won't be able to set the counter in the grey shaded Textview. In my case BDE name Madhu is displayed 3 times.But I don't need this. 3 is going to display in the grey shaded Textview.
Adapter Class:
public class PendingViewAdapter extends
RecyclerView.Adapter<PendingViewHolders> {
private List<PendingBO> itemList;
private Context context;
private int count=0;
public PendingViewAdapter(Context context, List<PendingBO> itemList) {
this.itemList = itemList;
this.context = context;
}
@Override
public PendingViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.pending_approval_row, null);
PendingViewHolders rcv = new PendingViewHolders(layoutView);
return rcv;
}
@Override
public void onBindViewHolder(PendingViewHolders holder, int position) {
final PendingBO pendingBO = itemList.get(position);
holder.txtOne.setText("BDE Name" + " : " + pendingBO.getEmpName());
// holder.txtRed.setText(pendingBO.getStatus());
holder.cardView.setCardBackgroundColor(Color.parseColor("#ffffff"));
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowLeadDetails(pendingBO);
}
});
}
public void ShowLeadDetails(PendingBO pendingBO){
Intent intent = new Intent(context, LeadDetailsActivity.class);
AppController.getInstance().pendingBO = pendingBO;
// context.startActivity(intent);
((Activity) context).startActivityForResult(intent,0);
((Activity) context).finish();
}
@Override
public int getItemCount() {
return this.itemList.size();
}
}
Upvotes: 0
Views: 55
Reputation: 2804
I would make an intermediate List, which I would search for doubles. Each time when finding a double, remove teh double and increase the counter on the original. When this routine has gone through, copy the List to the actual itemList.
Or of course do it on the itemList itself. May have efficiency advantages, I'd jsut do the intermediate List first for...easier thinking and sorting of steps.
Quick and dirty solution:
this.interList = itemList;
int i = 0;
while(i<this.interList.size()){
int j = 1;
while(j<this.interList.size()){
if(interList.get(i).Equals(interList.get(j)){
interList.remove(j);
interList.get(i).counter++;
} else j++;
}
}
this.itemList = this.interList;
Turns out, you can indeed do it without any intermediate list.
Upvotes: 1