How to implement multiple callback in RecyclerAdapter? - android

I have custom ServerRecyclerAdapter in which I implemented onLongClickListener, but now I am having problem where to implement OnClickListener
public class ServerRecyclerAdapter extends RecyclerView.Adapter<ServerRecyclerAdapter.ViewHolder> {
//Interface for callbacks
interface ActionCallback {
void onLongClickListener(Server server);
}
private Context context;
private List<Server> serverList;
private ActionCallback mActionCallbacks;
ServerRecyclerAdapter(Context context, List<Server> serverList) {
this.context = context;
this.serverList = serverList;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_recycler_server, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.bindData(position);
}
#Override
public int getItemCount() {
return serverList.size();
}
void updateData(List<Server> servers) {
this.serverList = servers;
notifyDataSetChanged();
}
//View Holder
class ViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
private TextView mNameTextView;
ViewHolder(View itemView) {
super(itemView);
itemView.setOnLongClickListener(this);
mNameTextView = itemView.findViewById(R.id.nameTextView);
}
void bindData(int position) {
Server server = serverList.get(position);
String servername = server.getServerName();
mNameTextView.setText(servername);
}
#Override
public boolean onLongClick(View v) {
if (mActionCallbacks != null) {
mActionCallbacks.onLongClickListener(serverList.get(getAdapterPosition()));
}
return true;
}
}
void addActionCallback(ActionCallback actionCallbacks) {
mActionCallbacks = actionCallbacks;
}

Try this
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
itemView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
if (mActionCallbacks != null) {
mActionCallbacks.onLongClickListener(serverList.get(getAdapterPosition()));
}
return true;
}
});
}

how about ...
extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener
then it will suggest you where to insert the override for that interface method.

For others how to solve this simple question :)
I've added in ActionCallback
void onClickListener(Server server);
and in ViewHolder
class ViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
private TextView mNameTextView;
ViewHolder(View itemView) {
super(itemView);
itemView.setOnLongClickListener(this);
itemView.setOnClickListener(this);
mNameTextView = itemView.findViewById(R.id.nameTextView);
}
.
.
.
#Override
public void onClick(View view) {
if (mActionCallbacks != null) {
mActionCallbacks.onClickListener(serverList.get(getAdapterPosition()));
}
}
Thx to #MikeM. for helping me solve it

Related

Should I create adapter for every recyclerview?

I am using diffutil for my recycler adapters and I need many recyclerview for categorization. Should I create adapter for every recyclerview? Same view, same type data, same functions, different data btw
If you check your recycler view's onBindViewHolder method it has your holder parameter which provides you with the instance of different ViewHolders you have and accordingly set the layout for the recycler view.
For example, in my case I had to use a single recyclerView adapter to create an instance Income as well as expense in a list.
This is how my onBindViewHolder looks:
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
DialogDetails d=new DialogDetails();
if (holder instanceof IncomeListHolder){
((IncomeListHolder)holder).categoryText.setText(expensesList.get(position).getCategory());
((IncomeListHolder)holder).incomeText.setText("+"+expensesList.get(position).getAmount());
((IncomeListHolder)holder).incomeText.setTextColor(context.getResources().getColor(R.color.income_color));
}
if (holder instanceof ExpensesListHolder){
((ExpensesListHolder) holder).category.setText(list.get(position-expensesList.size()).getCategory());
((ExpensesListHolder) holder).expenseText.setText("-"+list.get(position- expensesList.size()).getExpense());
((ExpensesListHolder) holder).expenseText.setTextColor(context.getResources().getColor(R.color.expense_color));
}
//.setText(String.valueOf(balanceList.get(position).getIncome()));
}
You also have to create separate viewHolders for all the list data you wish to display,like:
public class IncomeListHolder extends RecyclerView.ViewHolder {
TextView categoryText;
TextView incomeText;
public IncomeListHolder(#NonNull View itemView) {
super(itemView);
categoryText=itemView.findViewById(R.id.main_category_text_view);
incomeText=itemView.findViewById(R.id.expenses_text_view);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int position=getAdapterPosition();
if (listener!=null && position!=RecyclerView.NO_POSITION){
listener.getIncomeData(expensesList.get(position),view);
details.setUpdate(true);
}
}
});
}
}
public class ExpensesListHolder extends RecyclerView.ViewHolder{
TextView category;
TextView expenseText;
public ExpensesListHolder(#NonNull View itemView) {
super(itemView);
category=itemView.findViewById(R.id.main_category_text_view_2);
expenseText=itemView.findViewById(R.id.expenses_text_view_2);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int position=getAdapterPosition();
if (listener!=null && position!=RecyclerView.NO_POSITION){
listener.getExpenseData(list.get(position-expensesList.size()),view);
details.setUpdate(true);
}
}
});
}
}
My whole recycler view adapter:
public class IncomeListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
final int VIEW_TYPE_INCOME=0;
final int VIEW_TYPE_EXPENSE=1;
View view;
List<DataBaseEntity> expensesList=new ArrayList<>();
List<ExpenseDataEntity> list=new ArrayList<>();
Context context;
OnItemClickListener listener;
DialogDetails details=new DialogDetails();
public IncomeListAdapter(Context context) {
this.context = context;
}
//
// View v=LayoutInflater.from(context).inflate(R.layout.fragment_expense_home,null);
//// t=v.findViewById(R.id.income_text_view);
// }
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
if (viewType==VIEW_TYPE_INCOME) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.expenses_list, parent, false);
return new IncomeListHolder(view);
}
if (viewType==VIEW_TYPE_EXPENSE){
view=LayoutInflater.from(parent.getContext()).inflate(R.layout.expense_layout_list,parent,false);
return new ExpensesListHolder(view);
}
return null;
}
public interface OnItemClickListener{
void getIncomeData(DataBaseEntity dataBaseEntity,View view);
void getExpenseData(ExpenseDataEntity expenseDataEntity,View view);
}
public void setOnItemClickListener(OnItemClickListener listener){
this.listener=listener;
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
DialogDetails d=new DialogDetails();
if (holder instanceof IncomeListHolder){
((IncomeListHolder)holder).categoryText.setText(expensesList.get(position).getCategory());
((IncomeListHolder)holder).incomeText.setText("+"+expensesList.get(position).getAmount());
((IncomeListHolder)holder).incomeText.setTextColor(context.getResources().getColor(R.color.income_color));
}
if (holder instanceof ExpensesListHolder){
((ExpensesListHolder) holder).category.setText(list.get(position-expensesList.size()).getCategory());
((ExpensesListHolder) holder).expenseText.setText("-"+list.get(position- expensesList.size()).getExpense());
((ExpensesListHolder) holder).expenseText.setTextColor(context.getResources().getColor(R.color.expense_color));
}
//.setText(String.valueOf(balanceList.get(position).getIncome()));
}
public DataBaseEntity getDataAt(int position){
return expensesList.get(position);
}
public ExpenseDataEntity getExpenseAt(int position){
return list.get(position- expensesList.size());
}
#Override
public int getItemCount() {
return expensesList.size()+list.size();
}
#Override
public int getItemViewType(int position) {
if (position< expensesList.size()){
return VIEW_TYPE_INCOME;
}
if (position-expensesList.size()< list.size()){
return VIEW_TYPE_EXPENSE;
}
return -1;
}
public void setExpensesList(List<DataBaseEntity> expensesList){
this.expensesList=expensesList;
notifyDataSetChanged();
}
public void setList(List<ExpenseDataEntity> list){
this.list=list;
notifyDataSetChanged();
}
// public void setBalanceList(List<BalanceSheetEntity> balanceList){
// this.balanceList=balanceList;
// notifyDataSetChanged();
// }
public class IncomeListHolder extends RecyclerView.ViewHolder {
TextView categoryText;
TextView incomeText;
public IncomeListHolder(#NonNull View itemView) {
super(itemView);
categoryText=itemView.findViewById(R.id.main_category_text_view);
incomeText=itemView.findViewById(R.id.expenses_text_view);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int position=getAdapterPosition();
if (listener!=null && position!=RecyclerView.NO_POSITION){
listener.getIncomeData(expensesList.get(position),view);
details.setUpdate(true);
}
}
});
}
}
public class ExpensesListHolder extends RecyclerView.ViewHolder{
TextView category;
TextView expenseText;
public ExpensesListHolder(#NonNull View itemView) {
super(itemView);
category=itemView.findViewById(R.id.main_category_text_view_2);
expenseText=itemView.findViewById(R.id.expenses_text_view_2);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int position=getAdapterPosition();
if (listener!=null && position!=RecyclerView.NO_POSITION){
listener.getExpenseData(list.get(position-expensesList.size()),view);
details.setUpdate(true);
}
}
});
}
}
}

Unable to get Click action on RecyclerView

I am using RecyclerView in BottomSheet.The data is fetched successfuly but unable to get click action on the RecyclerView items. This is my BottomSheetAdapter code :
public class BottomSheetAdapter extends RecyclerView.Adapter<BottomSheetAdapter.ViewHolder> {
List<UserDetailsModel> userDetailsModelList;
Context context;
private Onitemclicklistenersuggestion listener;
public BottomSheetAdapter(List<UserDetailsModel> userDetailsModelList, Context context) {
this.userDetailsModelList = userDetailsModelList;
this.context = context;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_recycler_items, parent, false);
return new BottomSheetAdapter.ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
UserDetailsModel model = userDetailsModelList.get(position);
holder.firstNameLabel.setText(model.getFirst_name().trim());
}
#Override
public int getItemCount() {
return userDetailsModelList.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView firstNameLabel;
public ViewHolder(#NonNull View itemView) {
super(itemView);
firstNameLabel = itemView.findViewById(R.id.firstNameLabel);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (listener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.clicktoupdate(position);
}
}
}
}
public interface Onitemclicklistenersuggestion {
void clicktoupdate(int poistion);
}
public void setOnitemclicklistener(Onitemclicklistenersuggestion mlistener) {
listener = mlistener;
}
}
This is my BottomSheetDialog code :
public class BottomSheetDialog extends BottomSheetDialogFragment
implements BottomSheetAdapter.Onitemclicklistenersuggestion {
bottomSheetAdapter = new BottomSheetAdapter(userDetailsModelList, getActivity());
bottomSheetRecycler.setAdapter(bottomSheetAdapter);
bottomSheetRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
bottomSheetAdapter.setOnitemclicklistener(new BottomSheetAdapter.Onitemclicklistenersuggestion() {
#Override
public void clicktoupdate(int poistion) {
Log.e("Pos", "Pos");
}
});
bottomSheetAdapter.notifyDataSetChanged();
}
#Override
public void clicktoupdate(int poistion) {
Toast.makeText(getContext(), ""+poistion, Toast.LENGTH_SHORT).show();
}
But after clicking the RecyclerView items neither the Log or the Toast message shows up. Please help me fix it. Thanks in Millions.
Try setting the onClick logic inside your ViewHolder class.
So something like,
class ViewHolder extends RecyclerView.ViewHolder {
TextView firstNameLabel;
public ViewHolder(#NonNull View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// show a toast msg or whatever action you need...
}
});
firstNameLabel = itemView.findViewById(R.id.firstNameLabel);
}
}

Android RecyclerView onClick in different Activity

Everything works well and my onClick in my recyclerView is working in getting the positions of my items, but what my design calls for is to be able to click an item of the recyclerView and open up a new activity (as a popover or pop up). I can achieve this but my problems comes with the information I need to display on the popover. The information comes like this inside the activity (inside a Firebase value call)
attributeList.removeAll(attributeList);
for (DataSnapshot child : dataSnapshot.child("Attribute").getChildren()){
Attribute attribute = child.getValue(Attribute.class);
attribute_list newAttributeList = new attribute_list( attribute.Name + ": " + attribute.Value);
attributeList.add(newAttributeList);
}
attributeAdapter = new attribute_list_adapter(attributeList, getContext());
recyclerAttribute.setAdapter(attributeAdapter);
This works perfectly for displaying the information, but there's more then just a "value" and a "name" associated with the click.
Basically when I select an item, I need to get the position of the item clicked (which I have) and compare it to the position inside attributeList so I can call a Firebase call (or pass the data somehow) to the popover to display values from the "Attribute" class (such as Name, Value, Description, and another list (recyclerView).
My recyclerView:
public class attribute_list_adapter extends RecyclerView.Adapter<attribute_list_adapter.ViewHolder> {
private List<attribute_list> listItems;
private Context context;
public attribute_list_adapter(List<attribute_list> listItems, Context context) {
this.listItems = listItems;
this.context = context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.attribute_list, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
attribute_list listItem = listItems.get(position);
holder.txtTitle.setText(listItem.getTxtTitle());
}
#Override
public int getItemCount() {
return listItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtTitle;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
txtTitle = (TextView) itemView.findViewById(R.id.txtTitle);
}
#Override
public void onClick(View v) {
}
}
}
This is example:
public class attribute_list_adapter extends RecyclerView.Adapter<attribute_list_adapter.ViewHolder> {
private List<attribute_list> listItems;
private Context context;
public attribute_list_adapter(List<attribute_list> listItems, Context context) {
this.listItems = listItems;
this.context = context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.attribute_list, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.itemView.setOnClickListener(new View.onClickListener() {
#Override
public void onClick(View v) {
onItemClickListener.onItemClick(position);
}
});
}
#Override
public int getItemCount() {
return listItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView txtberita;
ImageView imgberita;
TextView txtnama;
public ViewHolder(View itemView) {
super(itemView);
txtnama = (TextView) itemView.findViewById(R.id.txtnama);
txtberita = (TextView) itemView.findViewById(R.id.txtberita);
imgberita = (ImageView) itemView.findViewById(R.id.imgberita);
}
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener){
this.onItemClickListener = onItemClickListener;
}
OnItemClickListener onItemClickListener;
public interface OnItemClickListener{
void onItemClick(int position);
}
}
your Activity. in Oncreate()
public class TestActivity extends AppCompatActivity implements attribute_list_adapter.OnItemClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
attribute_list_adapter adapter = new attribute_list_adapter(listItems, this);
adapter.setOnItemClickListener(this);
}
#Override
public void onItemClick(int position) {
// code here
}
}
Create an interface something like
public interface OnSingleItemClickListener{
void onSingleItemClick(int position);
}
Then implement it on your ViewHolder like this
public class ViewHolder extends RecyclerView.ViewHolder implements OnSingleItemClickListener {
public ViewHolder(View itemView) {
super(itemView);
}
#Override
void onSingleItemClick(int position){
if(listItems.get(position) == listItems.get(getAdapterPosition)){
// TODO do something here
}
}
now on your OnBindViewHolder inside your adapter you must do this.
holder.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
holder.onSingleItemClick(position);
}
}):

Slow application after image in RecyclerView

My app was working normally but got really slow after I included resized images in RecyclerView, why does this happen?
public class AlunoAdapter extends RecyclerView.Adapter<AlunoAdapter.AlunoViewHolder> {
private List<Aluno> alunos;
private Context context;
private static ItemClickListener clickListener;
private static LongItemClickListener longItemClickListener;
public AlunoAdapter(List<Aluno> Alunos, Context context) {
this.alunos = Alunos;
this.context = context;
}
#Override
public AlunoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.aluno_celula, parent, false);
return new AlunoViewHolder(view);
}
#Override
public void onBindViewHolder(AlunoViewHolder holder, int position) {
Aluno aluno = alunos.get(position);
holder.nome.setText(aluno.getNome());
if (aluno.getFoto() != null) {
Bitmap fotoAluno = BitmapFactory.decodeFile(aluno.getFoto());//
Bitmap fotoReduz = Bitmap.createScaledBitmap(fotoAluno, 100, 100, true);
holder.foto.setImageBitmap(fotoReduz);//
} else {
Drawable semFoto = context.getResources().getDrawable(R.drawable.ic_no_image3);
holder.foto.setImageDrawable(semFoto);
}
}
#Override
public int getItemCount() {
return alunos.size();
}
public void setClickListener(ItemClickListener itemClickListener) {
clickListener = itemClickListener;
}
public void setLongItemClickListenerClickListener(LongItemClickListener longItemClickListenerClickListener) {
longItemClickListener = longItemClickListenerClickListener;
}
public class AlunoViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
final TextView nome;
final ImageView foto;//
public AlunoViewHolder(View view) {
super(view);
nome = (TextView) view.findViewById(R.id.nome);
foto = (ImageView) view.findViewById(R.id.fotinha);//
view.setOnClickListener(this);
view.setOnLongClickListener(this);//nao tinha
}
#Override
public void onClick(View view) {
if (clickListener != null)
clickListener.onItemClick(view, getAdapterPosition(), false);
}
#Override
public boolean onLongClick(View view) {
if (longItemClickListener != null)
longItemClickListener.onItemClick(view, getAdapterPosition());
return false;
}
}
public interface ItemClickListener {
void onItemClick(View view, int position, boolean b);
}
public interface LongItemClickListener {
boolean onItemClick(View view, int position);
}
}
I'm a beginner in Android programming and I must be implementing something wrong.
You can use Glid library for smooth image loading in android.
Please refer below link for the library
https://github.com/bumptech/glide

How to implement alphabetical Section RecyclerView in android without any external library?

Hello all am new for android development am trying to make section recyclerview header like items must comes under first charc how can i achieve this so far i have done this with third party library now i like to do it myself please someone help me how to do this here what i have tried before:
public class accountheader extends StatelessSection implements View.OnClickListener{
private accountheader.OnItemClickListener onItemClickListener;
String title;
List<AccountModel> listobj;
Context context;
public accountheader(String title, List<AccountModel> list, Context context) {
super(R.layout.section_ex1_header, R.layout.recyclerviewitem);
this.title = title;
this.listobj = list;
this.context=context;
}
public void setOnItemClickListener(final accountheader.OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
#Override
public int getContentItemsTotal() {
return listobj.size();
}
#Override
public RecyclerView.ViewHolder getItemViewHolder(View view) {
return new ItemViewHolder(view);
}
#Override
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, final int position) {
final ItemViewHolder viewHolder = (ItemViewHolder) holder;
TextView companyname=viewHolder.CompanyName;
TextView companygroup=viewHolder.CompanyGroup;
TextView acm=viewHolder.AccountManager;
TextView companytype=viewHolder.CompanyType;
ImageView caption=viewHolder.caption;
viewHolder.click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(context, AccountView.class);
int name=listobj.get(position).getId();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.d("n",String.valueOf(name));
context.startActivity(intent);
}
});
companyname.setText(listobj.get(position).getCompanyName());
companygroup.setText(listobj.get(position).getCompanyGroup());
acm.setText(listobj.get(position).getAccountManagerText());
ColorGenerator generator = ColorGenerator.DEFAULT;
TextDrawable drawable = TextDrawable.builder()
.buildRound((listobj.get(position).getCompanyName().substring(0,1)).toUpperCase(), generator.getRandomColor());
viewHolder.caption.setImageDrawable(drawable);
}
#Override
public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
return new HeaderViewHolder(view);
}
#Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
headerHolder.tvTitle.setText(title);
}
#Override
public void onClick(View v) {
final RecyclerView recyclerView = (RecyclerView) v.getParent();
int position = recyclerView.getChildLayoutPosition(v);
if (position != RecyclerView.NO_POSITION) {
this.onItemClickListener.onItemClicked(position);
}
}
public interface OnItemClickListener {
void onItemClicked(int position);
}
}
class HeaderViewHolder extends RecyclerView.ViewHolder {
final TextView tvTitle;
public HeaderViewHolder(View view) {
super(view);
tvTitle = (TextView) view.findViewById(R.id.tvTitle);
}
}
class ItemViewHolder extends RecyclerView.ViewHolder {
View click;
TextView CompanyName;
TextView CompanyGroup;
TextView AccountManager;
TextView CompanyType;
ImageView caption;
ItemViewHolder(View itemView) {
super(itemView);
click=itemView;
CompanyName=(TextView)itemView.findViewById(R.id.header);
CompanyGroup=(TextView)itemView.findViewById(R.id.middle);
AccountManager=(TextView)itemView.findViewById(R.id.footer);
CompanyType=(TextView)itemView.findViewById(R.id.status);
caption=(ImageView)itemView.findViewById(R.id.imageView);
}
}
This is how i implemented in activity:
SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();
accountheader Accountheader=null;
for(char alphabet = 'A'; alphabet <= 'Z';alphabet++) {
List<AccountModel> contacts = getContactsWithLetter(alphabet,list);
Accountheader=new accountheader(String.valueOf(alphabet), contacts,getApplicationContext());
if (contacts.size() > 0) {
sectionAdapter.addSection(Accountheader);
}
}
recyclerView.setAdapter(sectionAdapter);
private List<AccountModel> getContactsWithLetter(char letter,List<AccountModel>list) {
List<AccountModel> contacts = new ArrayList<>();
for (AccountModel accountModel:list) {
if (accountModel.getCompanyGroup().charAt(0) == letter) {
contacts.add(accountModel);
}
}
return contacts;
}
How can i achieve this without any third party library can someone please guide me:

Categories

Resources