Skip to content Skip to sidebar Skip to footer

Check The Item Selected From The AutoCompleteTextView Already Exist In The RecyclerView

I have AutoCmpleteTextView and RecyclerView in my app. When I searched and selected an item from the AutCompleteTextView it will added to the RecyclerView. It worked very well. But

Solution 1:

Depending on the comments, if you want to check if the item if present in RecyclerView then try to do like this:

if (myRecyclerViewAdapter.getItemCount() > 0) {
    if (!isPresent(newName, myRecyclerViewAdapter)) {
        myRecyclerViewAdapter.add(1, newName, newQty, newPCode, newPlant);
    } else {
        Toast.makeText(getApplicationContext(), "Product Already in the List", Toast.LENGTH_SHORT).show();
    }
}

And isPresent can be defined like this:

private boolean isPresent(String name, MyRecyclerViewAdapter myRecyclerViewAdapter){
    boolean isPresent = false;
    for(int i = 0; i < myRecyclerViewAdapter.getItemCount(); i++){
            if(name.equalsIgnoreCase(myRecyclerViewAdapter.getItemName(i).toString())){
                isPresent = true;
                break;
            }
    }
    return isPresent;
}

Post a Comment for "Check The Item Selected From The AutoCompleteTextView Already Exist In The RecyclerView"