Example usage for android.widget AutoCompleteTextView setOnClickListener

List of usage examples for android.widget AutoCompleteTextView setOnClickListener

Introduction

In this page you can find the example usage for android.widget AutoCompleteTextView setOnClickListener.

Prototype

@Override
    public void setOnClickListener(OnClickListener listener) 

Source Link

Usage

From source file:org.onebusaway.android.ui.TripPlanFragment.java

private void setUpAutocomplete(AutoCompleteTextView tv, final int use) {
    ObaRegion region = Application.get().getCurrentRegion();

    // Use Google widget if available
    if (GoogleApiAvailability.getInstance()
            .isGooglePlayServicesAvailable(getContext()) == ConnectionResult.SUCCESS) {
        tv.setFocusable(false);/* w  w  w.  j a v a 2 s . c  o  m*/
        tv.setOnClickListener(new ProprietaryMapHelpV2.StartPlacesAutocompleteOnClick(use, this, region));
        return;
    }

    // else, set up autocomplete with Android geocoder

    tv.setAdapter(new PlacesAutoCompleteAdapter(getContext(), android.R.layout.simple_list_item_1, region));
    tv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CustomAddress addr = (CustomAddress) parent.getAdapter().getItem(position);

            if (use == USE_FROM_ADDRESS) {
                mFromAddress = addr;
                mBuilder.setFrom(mFromAddress);
            } else if (use == USE_TO_ADDRESS) {
                mToAddress = addr;
                mBuilder.setTo(mToAddress);
            }

            checkRequestAndSubmit();
        }
    });
}

From source file:de.grobox.liberario.DirectionsFragment.java

private void setToUI() {
    // To text input
    final AutoCompleteTextView to = (AutoCompleteTextView) mView.findViewById(R.id.to);
    final TextView toText = (TextView) mView.findViewById(R.id.toText);

    OnClickListener toListener = new OnClickListener() {
        @Override/*w  w w .  java 2s .c  o  m*/
        public void onClick(View view) {
            if (to.getText().length() > 0) {
                to.showDropDown();
            } else {
                handleInputClick(FavLocation.LOC_TYPE.TO);
            }
        }
    };

    to.setOnClickListener(toListener);
    toText.setOnClickListener(toListener);

    // To Location List for Dropdown
    final LocationAdapter locAdapter = new LocationAdapter(getActivity(), FavLocation.LOC_TYPE.TO);
    locAdapter.setFavs(true);
    locAdapter.setHome(true);
    to.setAdapter(locAdapter);
    to.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            handleLocationItemClick(locAdapter.getItem(position), view, FavLocation.LOC_TYPE.TO);
        }
    });

    // TODO implement something to allow change of homeLocation

    final ImageView toStatusButton = (ImageView) mView.findViewById(R.id.toStatusButton);
    toStatusButton.setImageDrawable(null);
    toStatusButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            handleInputClick(FavLocation.LOC_TYPE.TO);
        }
    });

    // clear from text button
    final ImageButton toClearButton = (ImageButton) mView.findViewById(R.id.toClearButton);
    toClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            to.requestFocus();
            clearLocation(FavLocation.LOC_TYPE.TO);
            toClearButton.setVisibility(View.GONE);
        }
    });

    // To text input changed
    to.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // show clear button
            if (s.length() > 0) {
                toClearButton.setVisibility(View.VISIBLE);
                // clear location
                setLocation(null, FavLocation.LOC_TYPE.TO, null, false);
            } else {
                toClearButton.setVisibility(View.GONE);
                clearLocation(FavLocation.LOC_TYPE.TO);
                // clear drop-down list
                locAdapter.resetList();
            }
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
}

From source file:de.grobox.liberario.DirectionsFragment.java

private void setFromUI() {
    // From text input
    final AutoCompleteTextView from = (AutoCompleteTextView) mView.findViewById(R.id.from);
    final TextView fromText = (TextView) mView.findViewById(R.id.fromText);

    OnClickListener fromListener = new OnClickListener() {
        @Override//from w  ww.  j a v a 2 s.  c om
        public void onClick(View view) {
            if (from.getText().length() > 0) {
                from.showDropDown();
            } else {
                handleInputClick(FavLocation.LOC_TYPE.FROM);
            }
        }
    };

    from.setOnClickListener(fromListener);
    fromText.setOnClickListener(fromListener);

    // From Location List for Dropdown
    final LocationAdapter locAdapter = new LocationAdapter(getActivity(), FavLocation.LOC_TYPE.FROM);
    locAdapter.setFavs(true);
    locAdapter.setHome(true);
    locAdapter.setGPS(true);
    from.setAdapter(locAdapter);
    from.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            handleLocationItemClick(locAdapter.getItem(position), view, FavLocation.LOC_TYPE.FROM);
        }
    });

    // TODO itemLongClickListener to change homeLocation

    final ImageView fromStatusButton = (ImageView) mView.findViewById(R.id.fromStatusButton);
    fromStatusButton.setImageDrawable(null);
    fromStatusButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            handleInputClick(FavLocation.LOC_TYPE.FROM);
        }
    });

    // clear from text button
    final ImageButton fromClearButton = (ImageButton) mView.findViewById(R.id.fromClearButton);
    fromClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            from.requestFocus();
            clearLocation(FavLocation.LOC_TYPE.FROM);
            fromClearButton.setVisibility(View.GONE);
        }
    });

    // From text input changed
    from.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // show clear button
            if (s.length() > 0) {
                fromClearButton.setVisibility(View.VISIBLE);
                // clear location
                setLocation(null, FavLocation.LOC_TYPE.FROM, null, false);
            } else {
                fromClearButton.setVisibility(View.GONE);
                clearLocation(FavLocation.LOC_TYPE.FROM);
                // clear drop-down list
                locAdapter.resetList();
            }

            cancelGpsButton();
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });
}

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   www .  j av  a  2 s .com*/
    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();
            }
        }
    });
}