質問

I have a custom ListView set up in my app.

I am not sure how or if it's possible to do but I want to know how can I have the Android search icon to allow user to search within the ListView. So as the search becomes relevant, the ListView scrolls to that position and changes the background drawable.

I am looking to implement the search inside the ActionBar like this:

enter image description here

役に立ちましたか?

解決

You need to implement the content provider component for your application. The "private" content provider will allow you to do "custom search" like you desire. As per documentation:

However, you do need your own provider to provide custom search suggestions in your own application.

The NotePad example can provide you with a good starting point on implementing a "private" content provider. By "private", i mean that you are not sharing the ListView data with any other app or process running on your device or remotely.

HTH

他のヒント

  1. You need to implement a Filter simply by implements Filter to your ListView adapter.
  2. Write how you will filter your results inside performFiltering(CharSequence constraint) method.
  3. All you need is to make a call inside your SearchView query text listeners.
  4. Invalidate the ListView with filtered results. Or get position of relevant item inside the Adapter data, and scroll using mListView.smoothScrollToPosition(int position)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top