List of usage examples for android.widget AutoCompleteTextView getAdapter
public ListAdapter getAdapter()
Returns a filterable list adapter used for auto completion.
From source file:de.grobox.liberario.StationsFragment.java
@Override public void onNetworkProviderChanged(NetworkProvider np) { if (mView == null) return;// w w w.j av a2s .c om LinearLayout departuresLayout = (LinearLayout) mView.findViewById(R.id.departuresLayout); if (np.hasCapabilities(Capability.DEPARTURES)) { departuresLayout.setVisibility(View.VISIBLE); // clear favorites for auto-complete AutoCompleteTextView stationView = ((AutoCompleteTextView) mView.findViewById(R.id.stationView)); if (stationView.getAdapter() != null) { ((LocationAdapter) stationView.getAdapter()).resetList(); } // clear text view setStation(null); // hide text clear button ImageButton stationClearButton = (ImageButton) mView.findViewById(R.id.stationClearButton); stationClearButton.setVisibility(View.GONE); } else { departuresLayout.setVisibility(View.GONE); } LinearLayout nearbyStationsLayout = (LinearLayout) mView.findViewById(R.id.nearbyStationsLayout); if (np.hasCapabilities(Capability.NEARBY_STATIONS)) { nearbyStationsLayout.setVisibility(View.VISIBLE); } else { nearbyStationsLayout.setVisibility(View.GONE); } }
From source file:cz.maresmar.sfm.view.WithExtraFragment.java
private void refreshExtraDataInUi() { if (mExtraData == null || mExtraData.length() == 0) { return;//from w ww . ja v a 2s. c om } try { JSONObject jsonObject = new JSONObject(mExtraData); int i = 0; for (ExtraFormat extraFormat : mExtrasFormat) { EditText extraEditText = mExtraUiBindings[i]; try { String extraValue = jsonObject.getString(extraFormat.code); extraEditText.setText(extraValue); if (extraFormat.valuesList.length != 0) { // Show all values in drop down (as setText disable another values) AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) extraEditText; ((ArrayAdapter<String>) autoCompleteTextView.getAdapter()).getFilter().filter(null); } } catch (JSONException e) { Timber.w(e, "Cannot parse saved extras for %s", extraFormat.code); // I can leave default values so user can change it } i++; } } catch (JSONException e) { Timber.w(e, "Cannot parse saved extras"); // I can leave default values so user can change it } }
From source file:de.grobox.liberario.DirectionsFragment.java
public void refreshFavs() { if (mView != null) { AutoCompleteTextView from = ((AutoCompleteTextView) mView.findViewById(R.id.from)); ((LocationAdapter) from.getAdapter()).resetList(); AutoCompleteTextView to = ((AutoCompleteTextView) mView.findViewById(R.id.to)); ((LocationAdapter) to.getAdapter()).resetList(); }/*w ww . j a va2 s . c om*/ }
From source file:de.grobox.liberario.DirectionsFragment.java
public void handleInputClick(FavLocation.LOC_TYPE loc_type) { AutoCompleteTextView textView; if (loc_type.equals(FavLocation.LOC_TYPE.FROM)) { textView = ((AutoCompleteTextView) mView.findViewById(R.id.from)); } else {/* w ww. j a v a 2 s. c om*/ textView = ((AutoCompleteTextView) mView.findViewById(R.id.to)); } LocationAdapter locAdapter = (LocationAdapter) textView.getAdapter(); int size = locAdapter.addFavs(); if (size > 0) { textView.showDropDown(); } else { Toast.makeText(getActivity(), getResources().getString(R.string.error_no_favs), Toast.LENGTH_SHORT) .show(); } }
From source file:com.mobicage.rogerthat.plugins.friends.RecommendServiceActivity.java
private void configureMailView() { T.UI();/*from ww w . ja va 2 s . co m*/ final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.recommend_email_text_field); emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>())); emailText.setThreshold(1); if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) { mService.postAtFrontOfBIZZHandler(new SafeRunnable() { @SuppressWarnings("unchecked") @Override protected void safeRun() throws Exception { L.d("RecommendServiceActivity getEmailAddresses"); List<String> emailList = ContactListHelper.getEmailAddresses(RecommendServiceActivity.this); ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter(); for (int i = 0; i < emailList.size(); i++) { a.add(emailList.get(i)); } a.notifyDataSetChanged(); L.d("RecommendServiceActivity gotEmailAddresses"); } }); } final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String email = emailText.getText().toString().trim(); if (RegexPatterns.EMAIL.matcher(email).matches()) { mFriendsPlugin.shareService(mServiceEmail, email); emailText.setText(null); UIUtils.hideKeyboard(RecommendServiceActivity.this, emailText); AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this); builder.setMessage(R.string.service_recommendation_sent); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } } }; ((Button) findViewById(R.id.recommend_email_button)).setOnClickListener(onClickListener); emailText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { onClickListener.onClick(view); return true; } return false; } }); }
From source file:com.mobicage.rogerthat.AddFriendsActivity.java
private void configureMailView() { T.UI();// w w w. jav a 2 s . c om final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_email_text_field); emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>())); emailText.setThreshold(1); if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) { mService.postAtFrontOfBIZZHandler(new SafeRunnable() { @SuppressWarnings("unchecked") @Override protected void safeRun() throws Exception { L.d("AddFriendsActivity getEmailAddresses"); List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.this); ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter(); for (int i = 0; i < emailList.size(); i++) { a.add(emailList.get(i)); } a.notifyDataSetChanged(); L.d("AddFriendsActivity gotEmailAddresses"); } }); } final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String email = emailText.getText().toString().trim(); if (RegexPatterns.EMAIL.matcher(email).matches()) { if (mFriendsPlugin.inviteFriend(email, null, null, true)) { emailText.setText(null); UIUtils.hideKeyboard(AddFriendsActivity.this, emailText); } else { UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed)); } } else { AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } } }; ((Button) findViewById(R.id.add_via_email_button)).setOnClickListener(onClickListener); emailText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { onClickListener.onClick(view); return true; } return false; } }); }
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 ww w . j ava2 s . c o m // 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: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);//from w w w . j a 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(); } } }); }