我想将SearchView添加到我的列表中,以便用户可以在列表视图中查找特定内容
MainActivity.java
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
List<Book> books;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
books = new ArrayList<>();
books.add(new Book("Rich Dad Poor Dad", "Rich Dad Poor Dad is a 1997 book written by Robert Kiyosaki and Sharon Lechter.", "Robert Kiyosaki"));
books.add(new Book("Awaken The Giant Within", "Wake up and take control of your life! From the bestselling author of Inner Strength, Unlimited Power, and MONEY Master the Game", "Anthony Robbins"));
mRecyclerView = findViewById(R.id.my_recyclerview);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mAdapter = new RecyclerViewAdapter(books, this);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
}
}