|
13 | 13 | import androidx.viewpager.widget.PagerAdapter; |
14 | 14 | import androidx.viewpager.widget.ViewPager; |
15 | 15 | import android.os.Bundle; |
| 16 | +import android.text.InputType; |
16 | 17 | import android.view.LayoutInflater; |
17 | 18 | import android.view.Menu; |
18 | 19 | import android.view.MenuItem; |
@@ -210,80 +211,86 @@ public void onPrepareOptionsMenu(Menu menu) { |
210 | 211 | searchView.clearFocus(); |
211 | 212 | } |
212 | 213 |
|
| 214 | + if (searchView != null) { |
| 215 | + searchView.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); |
| 216 | + } |
| 217 | + |
213 | 218 |
|
214 | 219 | searchView.setQueryHint(searchstring); |
215 | 220 | searchView.setIconified(false); |
216 | 221 | searchView.clearFocus(); |
217 | 222 | searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { |
218 | 223 | @Override |
219 | 224 | public boolean onQueryTextChange(String query) { |
220 | | - searchQuery = query; |
221 | | - TextView countrycountTextView = (TextView) getView().findViewById(R.id.countrycounttextview); |
222 | | - Country[] countries; |
223 | | - String selection; |
224 | | - switch (sectionNumber) { |
225 | | - case 2: |
226 | | - searchstring = query.trim(); |
227 | | - if( searchstring.trim().equals("")) { |
228 | | - searchstring = "Filter Countries/Areas"; |
229 | | - searchView.setQueryHint(searchstring); |
230 | | - } |
231 | | - selection = ((Spinner) getView().findViewById(R.id.listViewSpinner)).getSelectedItem().toString(); |
232 | | - countries = getCountriesBySearch(query, getCountriesByLevel(selection)); |
233 | | - if (countrycount != null) { |
234 | | - countrycountTextView.setVisibility(View.VISIBLE); |
235 | | - countrycountTextView.setText(String.valueOf(countrycount) + " results found for " + query.trim()); |
236 | | - countrycountTextView.announceForAccessibility(String.valueOf(countrycount) + " results found for " + query.trim()); |
237 | | - countrycountTextView.setContentDescription(String.valueOf(countrycount) + " results found for " + query.trim()); |
238 | | - countrycountTextView.setFocusable(true); |
239 | | - countrycountTextView.setFocusableInTouchMode(true); |
240 | | - } |
241 | | - else |
242 | | - { |
243 | | - countrycountTextView.setVisibility(View.GONE); |
244 | | - } |
245 | | - break; |
246 | | - case 3: |
247 | | - searchstring = query.trim(); |
248 | | - if( searchstring.trim().equals("")) { |
249 | | - searchstring = "Filter Countries/Areas"; |
250 | | - searchView.setQueryHint(searchstring); |
251 | | - } |
252 | | - selection = ((Spinner) getView().findViewById(R.id.listViewSpinner)).getSelectedItem().toString(); |
253 | | - countries = getCountriesBySearch(query, getCountriesByRegion(selection)); |
254 | | - if (countrycount != null) { |
255 | | - countrycountTextView.setVisibility(View.VISIBLE); |
256 | | - countrycountTextView.setText(String.valueOf(countrycount) + " results found for " + query.trim()); |
257 | | - countrycountTextView.announceForAccessibility(String.valueOf(countrycount) + " results found for " + query.trim()); |
258 | | - countrycountTextView.setContentDescription(String.valueOf(countrycount) + " results found for " + query.trim()); |
259 | | - countrycountTextView.setFocusable(true); |
260 | | - countrycountTextView.setFocusableInTouchMode(true); |
261 | | - } |
262 | | - else |
263 | | - { |
264 | | - countrycountTextView.setVisibility(View.GONE); |
265 | | - } |
266 | | - break; |
267 | | - default: |
268 | | - searchstring = query.trim(); |
269 | | - countries = getCountriesBySearch(query); |
270 | | - |
271 | | - if (countrycount != null) { |
272 | | - countrycountTextView.setVisibility(View.VISIBLE); |
273 | | - countrycountTextView.setText(String.valueOf(countrycount) + " results found for " + query.trim()); |
274 | | - countrycountTextView.announceForAccessibility(String.valueOf(countrycount) + " results found for " + query.trim()); |
275 | | - countrycountTextView.setContentDescription(String.valueOf(countrycount) + " results found for " + query.trim()); |
276 | | - countrycountTextView.setFocusable(true); |
277 | | - countrycountTextView.setFocusableInTouchMode(true); |
278 | | - } |
279 | | - else |
280 | | - { |
281 | | - countrycountTextView.setVisibility(View.GONE); |
282 | | - } |
| 225 | + boolean check_alphabetOnly = query.matches("[a-zA-Z ]+"); |
| 226 | + if (check_alphabetOnly) { |
| 227 | + searchQuery = query; |
| 228 | + TextView countrycountTextView = (TextView) getView().findViewById(R.id.countrycounttextview); |
| 229 | + Country[] countries; |
| 230 | + String selection; |
| 231 | + switch (sectionNumber) { |
| 232 | + case 2: |
| 233 | + searchstring = query.trim(); |
| 234 | + if (searchstring.trim().equals("")) { |
| 235 | + searchstring = "Filter Countries/Areas"; |
| 236 | + searchView.setQueryHint(searchstring); |
| 237 | + } |
| 238 | + selection = ((Spinner) getView().findViewById(R.id.listViewSpinner)).getSelectedItem().toString(); |
| 239 | + countries = getCountriesBySearch(query, getCountriesByLevel(selection)); |
| 240 | + if (countrycount != null) { |
| 241 | + countrycountTextView.setVisibility(View.VISIBLE); |
| 242 | + countrycountTextView.setText(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 243 | + countrycountTextView.announceForAccessibility(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 244 | + countrycountTextView.setContentDescription(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 245 | + countrycountTextView.setFocusable(true); |
| 246 | + countrycountTextView.setFocusableInTouchMode(true); |
| 247 | + } else { |
| 248 | + countrycountTextView.setVisibility(View.GONE); |
| 249 | + } |
| 250 | + break; |
| 251 | + case 3: |
| 252 | + searchstring = query.trim(); |
| 253 | + if (searchstring.trim().equals("")) { |
| 254 | + searchstring = "Filter Countries/Areas"; |
| 255 | + searchView.setQueryHint(searchstring); |
| 256 | + } |
| 257 | + selection = ((Spinner) getView().findViewById(R.id.listViewSpinner)).getSelectedItem().toString(); |
| 258 | + countries = getCountriesBySearch(query, getCountriesByRegion(selection)); |
| 259 | + if (countrycount != null) { |
| 260 | + countrycountTextView.setVisibility(View.VISIBLE); |
| 261 | + countrycountTextView.setText(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 262 | + countrycountTextView.announceForAccessibility(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 263 | + countrycountTextView.setContentDescription(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 264 | + countrycountTextView.setFocusable(true); |
| 265 | + countrycountTextView.setFocusableInTouchMode(true); |
| 266 | + } else { |
| 267 | + countrycountTextView.setVisibility(View.GONE); |
| 268 | + } |
| 269 | + break; |
| 270 | + default: |
| 271 | + searchstring = query.trim(); |
| 272 | + countries = getCountriesBySearch(query); |
| 273 | + |
| 274 | + if (countrycount != null) { |
| 275 | + countrycountTextView.setVisibility(View.VISIBLE); |
| 276 | + countrycountTextView.setText(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 277 | + countrycountTextView.announceForAccessibility(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 278 | + countrycountTextView.setContentDescription(String.valueOf(countrycount) + " results found for " + query.trim()); |
| 279 | + countrycountTextView.setFocusable(true); |
| 280 | + countrycountTextView.setFocusableInTouchMode(true); |
| 281 | + } else { |
| 282 | + countrycountTextView.setVisibility(View.GONE); |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + CountryListAdapter itemsAdapter = new CountryListAdapter(getActivity(), countries, 1); |
| 287 | + ListView listView = (ListView) getView().findViewById(R.id.listView); |
| 288 | + listView.setAdapter(itemsAdapter); |
| 289 | + }else{ |
| 290 | + if( !searchQuery.trim().equals("")) { |
| 291 | + searchView.setQuery(searchQuery, false); |
| 292 | + } |
283 | 293 | } |
284 | | - CountryListAdapter itemsAdapter = new CountryListAdapter(getActivity(), countries, 1); |
285 | | - ListView listView = (ListView) getView().findViewById(R.id.listView); |
286 | | - listView.setAdapter(itemsAdapter); |
287 | 294 | return false; |
288 | 295 | } |
289 | 296 |
|
|
0 commit comments