List of usage examples for android.widget AutoCompleteTextView setOnItemClickListener
public void setOnItemClickListener(AdapterView.OnItemClickListener l)
Sets the listener that will be notified when the user clicks an item in the drop down list.
From source file:de.spiritcroc.modular_remote.Util.java
public static void suggestPreviousIps(final Fragment fragment, final AutoCompleteTextView textView) { Activity activity = fragment.getActivity(); final TcpConnectionManager tcpConnectionManager = TcpConnectionManager .getInstance(activity.getApplicationContext()); textView.setAdapter(new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1, tcpConnectionManager.getConnectionSuggestions())); if (fragment instanceof ReceiverIpSelectorUser) { textView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// ww w.j ava 2 s . c om public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TcpConnectionManager.TcpConnection connection = tcpConnectionManager .getTcpConnection(textView.getText().toString()); ((ReceiverIpSelectorUser) fragment).setReceiverType(connection.getType()); } }); } }
From source file:org.example.sinartweather.CityFinderActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cityfinder_layout); AutoCompleteTextView edt = (AutoCompleteTextView) this.findViewById(R.id.edtCity); CityAdapter adpt = new CityAdapter(this, null); edt.setAdapter(adpt);//from ww w . j a v a2 s . c o m getActionBar().setDisplayHomeAsUpEnabled(true); edt.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CityResult result = (CityResult) parent.getItemAtPosition(position); SharedPreferences sharedPref = PreferenceManager .getDefaultSharedPreferences(CityFinderActivity.this); //Log.d("SwA", "WOEID [" + result.getWoeid() + "]"); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("woeid", result.getWoeid()); editor.putString("cityName", result.getCityName()); editor.putString("country", result.getCountry()); editor.commit(); NavUtils.navigateUpFromSameTask(CityFinderActivity.this); } }); }
From source file:com.survivingwithandroid.weather.settings.CityFinderActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cityfinder_layout); AutoCompleteTextView edt = (AutoCompleteTextView) this.findViewById(R.id.edtCity); CityAdapter adpt = new CityAdapter(this, null); edt.setAdapter(adpt);/*from www . j a va 2s . co m*/ getActionBar().setDisplayHomeAsUpEnabled(true); edt.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CityResult result = (CityResult) parent.getItemAtPosition(position); SharedPreferences sharedPref = PreferenceManager .getDefaultSharedPreferences(CityFinderActivity.this); //Log.d("SwA", "WOEID [" + result.getWoeid() + "]"); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("woeid", result.getWoeid()); editor.putString("cityName", result.getCityName()); editor.putString("country", result.getCountry()); editor.commit(); NavUtils.navigateUpFromSameTask(CityFinderActivity.this); } }); }
From source file:de.grobox.liberario.SetHomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.activity_set_home); getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_action_home); setTitle(getString(R.string.home_dialog_title)); Intent intent = getIntent();/*from w w w. j av a 2s .c om*/ // show new home text if (!intent.getBooleanExtra("new", true)) { findViewById(R.id.homeMsgView).setVisibility(View.GONE); } // home location TextView final AutoCompleteTextView homeView = (AutoCompleteTextView) findViewById(R.id.homeView); LocationAdapter locAdapter = new LocationAdapter(this, FavLocation.LOC_TYPE.FROM, true); locAdapter.setFavs(true); homeView.setAdapter(locAdapter); homeView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { Location loc = (Location) parent.getItemAtPosition(position); homeView.setText(loc.uniqueShortName()); homeView.setTag(loc); homeView.requestFocus(); // hide soft-keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(homeView.getWindowToken(), 0); } }); // clear from text button final ImageButton homeClearButton = (ImageButton) findViewById(R.id.homeClearButton); homeClearButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { homeView.setText(""); homeView.requestFocus(); homeView.setTag(null); homeClearButton.setVisibility(View.GONE); } }); // When text changed homeView.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // clear saved station homeView.setTag(null); // show clear button homeClearButton.setVisibility(View.VISIBLE); } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } }); // station name favorites button findViewById(R.id.homeFavButton).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int size = ((LocationAdapter) homeView.getAdapter()).addFavs(); if (size > 0) { homeView.showDropDown(); } else { Toast.makeText(v.getContext(), getResources().getString(R.string.error_no_favs), Toast.LENGTH_SHORT).show(); } } }); // OK Button Button okButton = (Button) findViewById(R.id.okButton); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (homeView.getTag() != null && homeView.getTag() instanceof Location) { // save home location in file FavDB.setHome(v.getContext(), (Location) homeView.getTag()); Intent returnIntent = new Intent(); setResult(RESULT_OK, returnIntent); close(v); } else { Toast.makeText(v.getContext(), getResources().getString(R.string.error_only_autocomplete_station), Toast.LENGTH_SHORT) .show(); } } }); // Cancel Button Button cancelButton = (Button) findViewById(R.id.cancelButton); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent returnIntent = new Intent(); setResult(RESULT_CANCELED, returnIntent); close(v); } }); }
From source file:com.ant.sunshine.app.activities.MainActivity.java
private void initSearchView() { AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); autoCompleteTextView.setOnItemClickListener(mAutocompleteClickListener); adapter = new PlacesAdapter(this, null); autoCompleteTextView.setAdapter(adapter); searchView.setOnQueryTextListener(getOnQueryTextListener()); searchView.setIconifiedByDefault(true); }
From source file:de.grobox.liberario.StationsFragment.java
private void setDeparturesView() { // station name TextView final AutoCompleteTextView stationView = (AutoCompleteTextView) mView.findViewById(R.id.stationView); LocationAdapter locAdapter = new LocationAdapter(getActivity(), FavLocation.LOC_TYPE.FROM, true); locAdapter.setFavs(true);//ww w. ja v a 2 s . co m stationView.setAdapter(locAdapter); stationView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { setStation((Location) parent.getItemAtPosition(position)); stationView.requestFocus(); // hide soft-keyboard InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(stationView.getWindowToken(), 0); } }); // clear from text button final ImageButton stationClearButton = (ImageButton) mView.findViewById(R.id.stationClearButton); stationClearButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setStation(null); stationView.requestFocus(); } }); // When text changed stationView.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // clear saved station stationView.setTag(null); // show clear button if (s.length() > 0) { stationClearButton.setVisibility(View.VISIBLE); } else { stationClearButton.setVisibility(View.GONE); } } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } }); // TODO adapt like in DirectionsFragment // station name favorites button OnClickListener stationViewListener = new OnClickListener() { @Override public void onClick(View v) { int size = ((LocationAdapter) stationView.getAdapter()).addFavs(); if (size > 0) { stationView.showDropDown(); } else { Toast.makeText(getActivity(), getResources().getString(R.string.error_no_favs), Toast.LENGTH_SHORT).show(); } } }; mView.findViewById(R.id.stationFavButton).setOnClickListener(stationViewListener); stationView.setOnClickListener(stationViewListener); // home station button ImageButton stationHomeButton = (ImageButton) mView.findViewById(R.id.stationHomeButton); stationHomeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Location home = FavDB.getHome(getActivity()); if (home != null) { queryForStations(home); } else { Intent intent = new Intent(getActivity(), SetHomeActivity.class); intent.putExtra("new", true); startActivityForResult(intent, MainActivity.CHANGED_HOME); } } }); // Home Button Long Click stationHomeButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(getActivity(), SetHomeActivity.class); intent.putExtra("new", false); startActivityForResult(intent, MainActivity.CHANGED_HOME); return true; } }); // Find Departures Search Button Button stationButton = (Button) mView.findViewById(R.id.stationButton); stationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (stationView.getTag() != null && stationView.getTag() instanceof Location) { // use location to query departures Location location = (Location) stationView.getTag(); if (!location.hasId()) { Toast.makeText(getActivity(), getResources().getString(R.string.error_no_proper_station), Toast.LENGTH_SHORT).show(); return; } queryForStations(location); } else { Toast.makeText(getActivity(), getResources().getString(R.string.error_only_autocomplete_station), Toast.LENGTH_SHORT) .show(); } } }); }
From source file:com.robwilliamson.healthyesther.fragment.dialog.AbstractAddNamedDialogFragment.java
@Override public void onResume() { super.onResume(); View view = Utils.checkNotNull(getView()); Context context = Utils.checkNotNull(view.getContext()); getNameTitle().setText(context.getText(valueNameId())); AutoCompleteTextView name = getNameTextView(); name.setCompletionHint(getView().getContext().getText(valueCompletionHintId())); name.addTextChangedListener(new TextWatcher() { @Override/*www .jav a 2 s .c o m*/ public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String text = s.toString(); AbstractAddNamedDialogFragment.this.newNameEntered(text); } @Override public void afterTextChanged(Editable s) { } }); name.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String suggestion = (String) parent.getAdapter().getItem(position); AbstractAddNamedDialogFragment.this.suggestionSelected(suggestion, mSuggestions.get(suggestion)); } }); getOkButton().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onOk(); dismiss(); } }); if (contentLayoutId() != null && !mInflatedContent) { View.inflate(getView().getContext(), contentLayoutId(), getContentArea()); mInflatedContent = true; } updateSuggestionAdapter(); }
From source file:com.google.android.gms.location.sample.geofencing.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); startService(new Intent(this, GsmService.class)); MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); GeoFenceApp.getLocationUtilityInstance().initialize(this); dataSource = GeoFenceApp.getInstance().getDataSource(); TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String networkOperator = tel.getNetworkOperator(); int mcc = 0, mnc = 0; if (networkOperator != null) { mcc = Integer.parseInt(networkOperator.substring(0, 3)); mnc = Integer.parseInt(networkOperator.substring(3)); }//from w w w .j a va 2 s. co m Log.i("", "mcc:" + mcc); Log.i("", "mnc:" + mnc); final AutoCompleteTextView autocompleteView = (AutoCompleteTextView) findViewById(R.id.autocomplete); mAdapter = new PlacesAutoCompleteAdapter(this, R.layout.text_adapter); autocompleteView.setAdapter(mAdapter); autocompleteView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Get data associated with the specified position // in the list (AdapterView) String description = (String) parent.getItemAtPosition(position); place = description; Toast.makeText(MainActivity.this, description, Toast.LENGTH_SHORT).show(); try { Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocationName(description, 1); Address address = addresses.get(0); if (addresses.size() > 0) { autocompleteView.clearFocus(); //inputManager.hideSoftInputFromWindow(autocompleteView.getWindowToken(), 0); LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude()); Location location = new Location("Searched_Location"); location.setLatitude(latLng.latitude); location.setLongitude(latLng.longitude); setupMApIfNeeded(latLng); //setUpMapIfNeeded(location); //searchBar.setVisibility(View.GONE); //searchBtn.setVisibility(View.VISIBLE); } } catch (Exception e) { e.printStackTrace(); } } }); // Get the UI widgets. mAddGeofencesButton = (Button) findViewById(R.id.add_geofences_button); mRemoveGeofencesButton = (Button) findViewById(R.id.remove_geofences_button); // Empty list for storing geofences. mGeofenceList = new ArrayList<Geofence>(); // Initially set the PendingIntent used in addGeofences() and removeGeofences() to null. mGeofencePendingIntent = null; // Retrieve an instance of the SharedPreferences object. mSharedPreferences = getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, MODE_PRIVATE); // Get the value of mGeofencesAdded from SharedPreferences. Set to false as a default. mGeofencesAdded = mSharedPreferences.getBoolean(Constants.GEOFENCES_ADDED_KEY, false); setButtonsEnabledState(); // Get the geofences used. Geofence data is hard coded in this sample. populateGeofenceList(); // Kick off the request to build GoogleApiClient. buildGoogleApiClient(); autocompleteView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { final String value = s.toString(); // Remove all callbacks and messages mThreadHandler.removeCallbacksAndMessages(null); // Now add a new one mThreadHandler.postDelayed(new Runnable() { @Override public void run() { // Background thread mAdapter.resultList = mAdapter.mPlaceAPI.autocomplete(value); // Footer if (mAdapter.resultList.size() > 0) mAdapter.resultList.add("footer"); // Post to Main Thread mThreadHandler.sendEmptyMessage(1); } }, 500); } @Override public void afterTextChanged(Editable s) { //doAfterTextChanged(); } }); if (mThreadHandler == null) { // Initialize and start the HandlerThread // which is basically a Thread with a Looper // attached (hence a MessageQueue) mHandlerThread = new HandlerThread(TAG, android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); // Initialize the Handler mThreadHandler = new Handler(mHandlerThread.getLooper()) { @Override public void handleMessage(Message msg) { if (msg.what == 1) { ArrayList<String> results = mAdapter.resultList; if (results != null && results.size() > 0) { runOnUiThread(new Runnable() { @Override public void run() { mAdapter.notifyDataSetChanged(); //stuff that updates ui } }); } else { runOnUiThread(new Runnable() { @Override public void run() { //stuff that updates ui mAdapter.notifyDataSetInvalidated(); } }); } } } }; } GetID(); }
From source file:ru.orangesoftware.financisto.activity.CategorySelector.java
private void initAutoCompleteFilter(final AutoCompleteTextView filterTxt) { // init only after it's toggled autoCompleteAdapter = TransactionUtils.createCategoryFilterAdapter(activity, db); filterTxt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_FILTER); filterTxt.setThreshold(1);//w w w . j a v a 2 s . c o m filterTxt.setOnFocusChangeListener((view, hasFocus) -> { if (hasFocus) { filterTxt.setAdapter(requireNonNull(autoCompleteAdapter)); filterTxt.selectAll(); } }); filterTxt.setOnItemClickListener((parent, view, position, id) -> { activity.onSelectedId(R.id.category, id); ToggleButton toggleBtn = (ToggleButton) filterTxt.getTag(); toggleBtn.performClick(); }); }
From source file:com.openerp.addons.idea.product.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.Dash_Board: Dash_Board detail = new Dash_Board(); FragmentListener frag = (FragmentListener) getActivity(); frag.startDetailFragment(detail); return true; case R.id.Search_product: final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.product_search_custom_dialog); // dialog.setTitle("Product Search"); dialog.setOnCancelListener(new OnCancelListener() { @Override// ww w.j av a 2s . co m public void onCancel(DialogInterface dialog) { dialog.dismiss(); } }); AutoCompleteTextView autotext = (AutoCompleteTextView) dialog .findViewById(R.id.autoCompleteTextView_product_search); final ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, OEHelper.datatemplate); TextView txv = (TextView) dialog.findViewById(R.id.textView1); Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Georgia.ttf"); autotext.setTypeface(font, Typeface.BOLD); autotext.setAdapter(adapter); txv.setTypeface(font, Typeface.BOLD); autotext.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String name = adapter.getItem(arg2).toString(); callmethod_for_position_productdetail(OEHelper.datatemplate.indexOf(name)); dialog.dismiss(); } }); dialog.show(); return true; } return true; }