Last active
October 5, 2017 03:48
-
-
Save khatthaphone/270dfc7425d7067a11c884187683e69a to your computer and use it in GitHub Desktop.
This file contains 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
<activity | |
android:name=".activity.MainActivity"> | |
<!--ເພີ່ມບ່ອນນີ້--> | |
<meta-data | |
android:name="android.app.searchable" | |
android:resource="@xml/searchable" /> | |
</activity> |
This file contains 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 | |
public boolean onCreateOptionsMenu(Menu menu) { | |
MenuInflater inflater = getMenuInflater(); | |
inflater.inflate(R.menu.options_menu, menu); | |
// Associate searchable configuration with the SearchView | |
SearchManager searchManager = | |
(SearchManager) getSystemService(Context.SEARCH_SERVICE); | |
SearchView searchView = | |
(SearchView) menu.findItem(R.id.search).getActionView(); | |
searchView.setSearchableInfo( | |
searchManager.getSearchableInfo(getComponentName())); | |
searchView.setIconifiedByDefault(false) | |
searchView.isQueryRefinementEnabled(true) | |
// ສ່ວນຕໍ່ຈາກນີ້ຈະປົນໆພາສາ kotlin ເດີ້ | |
// Handling search | |
searchView.setOnQueryTextListener(object: SearchView.OnQueryTextListener { | |
// ຕອນຜູ່ໃຊ້ submit | |
override fun onQueryTextSubmit(query: String?): Boolean { | |
// ໃຫ້ເຮັດຫຍັງບາງຢ່າງຢູ່ນີ້, eg. ດຶງຂໍ້ມູນມາໂຊຈາກ pararmeter query ແລ້ວເອົາໄປອັບເດດ ListView | |
ແທນທີ່ຈະ submit ແລ້ວດຶງໜ້າຕໍ່ໄປແມ່ນໃຫ້ອ້ງເອົາຄຳມາໃສ່ຊື່ໆ, ເປັນ onQueryTextChange ທຳມະດາ ເຮັດແບບນີ້ໄດ້ | |
// searchView.setQuery(query, false) | |
onQueryTextChange(query)*/ | |
// ສຳຄັນ, ສົ່ງຄືນ true ເພື່ອໃຫ້ລະບົບຮູ້ວ່າເຮົາຈັດການທຸກຢ່າງຮຽບຮ້ອຍແລ້ວ ບໍ່ຕ້ອປ່ຽນໄປໜ້າຕໍ່ໄປຄືຢູ່ docs ພາສ້າງ SearchableActivity ຫັ້ນ | |
return true | |
} | |
// ເມື່ອຜູ່ໃຊ້ພິມ | |
override fun onQueryTextChange(newText: String): Boolean { | |
// ໃຫ້ເຮັດຫຍັງບາງຢ່າງຢູ່ນີ້, eg. ດຶງຂໍ້ມູນມາໂຊຈາກ pararmeter newText ແລ້ວເອົາໄປອັບເດດ ListView | |
return true | |
} | |
}) | |
return true; | |
} |
This file contains 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
<!--ເອົາໄວ້ໃນ res/xml/searchable.xml--> | |
<?xml version="1.0" encoding="utf-8"?> | |
<!--To enable recent search suggestion add android:searchSuggestAuthority="devzy.com.saylao_eng.manager.SearchRecentSuggestionProvider"--> | |
<searchable xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:label="@string/app_name" | |
android:hint="@string/search_hint"> | |
</searchable> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment