This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| implementation 'com.android.support:recyclerview-v7:28.0.0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <android.support.constraint.ConstraintLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity"> | |
| <android.support.v7.widget.SearchView |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Name { | |
| private String name; | |
| Name(String name) { | |
| this.name = name; | |
| } | |
| public String getName() { | |
| return name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| xmlns:tools="http://schemas.android.com/tools"> | |
| <android.support.v7.widget.AppCompatTextView | |
| android:id="@+id/tv_name" | |
| android:layout_width="wrap_content" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Context; | |
| import android.support.annotation.NonNull; | |
| import android.support.v7.widget.AppCompatTextView; | |
| import android.support.v7.widget.RecyclerView; | |
| import android.view.LayoutInflater; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.Adapter; | |
| import android.widget.Filter; | |
| import android.widget.Filterable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AnimalsAdapter extends RecyclerView.Adapter<AnimalsAdapter.AnimalsViewHolder> implements Filterable { | |
| private Context context; | |
| private List<Name> nameList; | |
| private List<Name> filteredNameList; | |
| AnimalsAdapter(Context context, List<Name> nameList) { | |
| super(); | |
| this.context = context; | |
| this.nameList = nameList; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * <p>Returns a filter that can be used to constrain data with a filtering | |
| * pattern.</p> | |
| * | |
| * <p>This method is usually implemented by {@link Adapter} | |
| * classes.</p> | |
| * | |
| * @return a filter used to constrain data | |
| */ | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| searchView = findViewById(R.id.search_view); | |
| recyclerView = findViewById(R.id.recycler_view); | |
| addNameToList("Giraffe"); | |
| addNameToList("Tiger"); | |
| addNameToList("Rhinoceros"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
| @Override | |
| public boolean onQueryTextSubmit(String queryString) { | |
| animalsAdapter.getFilter().filter(queryString); | |
| return false; | |
| } | |
| @Override | |
| public boolean onQueryTextChange(String queryString) { | |
| animalsAdapter.getFilter().filter(queryString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private List<Name> nameList = new ArrayList<>(); | |
| private SearchView searchView; | |
| private RecyclerView recyclerView; | |
| private AnimalsAdapter animalsAdapter; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| searchView = findViewById(R.id.search_view); |
OlderNewer