Example usage for android.widget AutoCompleteTextView setAdapter

List of usage examples for android.widget AutoCompleteTextView setAdapter

Introduction

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

Prototype

public <T extends ListAdapter & Filterable> void setAdapter(T adapter) 

Source Link

Document

Changes the list of data used for auto completion.

Usage

From source file:com.vaquerosisd.projectmanager.TaskList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.task_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem);
    Button clearSearchTask = (Button) searchItem.getActionView().findViewById(R.id.actionBar_ClearSearch);
    final AutoCompleteTextView searchTask = (AutoCompleteTextView) searchItem.getActionView()
            .findViewById(R.id.actionBar_SearchItemEditText);

    //Get all tasks names and add them to an adapter for the AutoCompleteTextView
    List<Task> allTasks = db.getAllTasks(projectId);
    String[] tasksNames = new String[allTasks.size()];
    for (int i = 0; i < allTasks.size(); i++)
        tasksNames[i] = allTasks.get(i).getTaskName();

    ArrayAdapter<String> tasksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            tasksNames);//from  w  ww  . j  av  a 2 s. c o  m
    searchTask.setAdapter(tasksAdapter);
    searchTask.setThreshold(1);

    //Clear text of search AutoCompleteTextView
    clearSearchTask.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            searchTask.setText("");
        }
    });

    searchTask.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
            } else {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
            }
        }
    });

    //Search task
    searchTask.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //When the user press "DONE" key, select the task
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                String project = searchTask.getText().toString();
                searchTask(project);
                //Hide keyboard
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchTask.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                return true;
            }
            return false;
        }
    });
    return true;
}

From source file:pro.jariz.reisplanner.fragments.PlannerFragment.java

void Render(NSStation[] nsStations, final View x, final Context context) {

    AutoCompleteTextView auto = (AutoCompleteTextView) x.findViewById(R.id.AutoCompleteTextView1);
    AutoCompleteTextView auto2 = (AutoCompleteTextView) x.findViewById(R.id.AutoCompleteTextView2);
    AutoCompleteTextView auto3 = (AutoCompleteTextView) x.findViewById(R.id.AutoCompleteTextView3);

    ArrayList<String> fullnames = new ArrayList<String>();
    CardUI mCardView = (CardUI) x.findViewById(R.id.cardsview);
    mCardView.setSwipeable(true);//from   www .ja va2s  . c  om
    CardStack stack = new CardStack();
    stack.setTitle("Recentelijke stations");

    for (Integer i = 0; i < nsStations.length; i++) {
        fullnames.add((nsStations[i]).Namen.Lang);
        if (i < 5)
            stack.add(new StationCard((nsStations[i]).Namen.Lang));
    }
    mCardView.addStack(stack);

    //draw time
    auto.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, fullnames));
    auto2.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, fullnames));
    auto3.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, fullnames));
    mCardView.refresh();

    //stacktitle, do you even #HOLO?
    stack.setTitleTypeFace(Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-ThinItalic.ttf"));
}

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  ww . j  a va 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:com.mobicage.rogerthat.AddFriendsActivity.java

private void configureMailView() {
    T.UI();//from  ww w .  j  a v  a2s. com
    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:edu.rosehulman.grocerydroid.ItemDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_dialog_item, container, false);

    // EditText nameBox = (EditText) view.findViewById(R.id.item_name_box);
    AutoCompleteTextView nameBox = (AutoCompleteTextView) view.findViewById(R.id.item_name_box);

    nameBox.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);

    //      String[] names = new String[] { "Bob", "Joe", "Caleb", "Jonathan",
    //            "Elise" };

    String[] foodNames = getResources().getStringArray(R.array.food_names);

    //      ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(
    //            getActivity(), android.R.layout.simple_list_item_1, names);
    ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(getActivity(), R.layout.dropdown_item,
            foodNames);//from w ww  .  j  a v  a2 s.  co m

    // android.R.layout.sherlock.* both white/invisible
    // android.R.layout.
    // simple_spinner_item too thin
    // simple list item 2: crash
    // activity_list_item crash
    //simple_spinner_dropdown_item

    nameBox.setAdapter(autoAdapter);

    // mEditIcon.setOnKeyListener(new OnKeyListener() {
    // @Override
    // public boolean onKey(View v, int keyCode, KeyEvent event) {
    // // If the event is a key-down event on the "enter" button
    // if ((event.getAction() == KeyEvent.ACTION_DOWN)
    // && (keyCode == KeyEvent.KEYCODE_ENTER)) {
    // Toast.makeText(StockActivity.this, tv.getText(),
    // Toast.LENGTH_SHORT).show();
    // return true;
    // }
    // return false;
    // }
    // });

    EditText priceBox = (EditText) view.findViewById(R.id.item_price_box);
    priceBox.setInputType(InputType.TYPE_CLASS_PHONE);
    // priceBox.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);

    // first true : is signed, second one : is decimal
    priceBox.setKeyListener(new DigitsKeyListener(false, true));

    EditText sizeBox = (EditText) view.findViewById(R.id.item_unit_size_box);
    sizeBox.setText("" + mItem.getUnitSize());

    Spinner unitSpinner = (Spinner) view.findViewById(R.id.item_unit_label_spinner);
    ArrayAdapter<Item.UnitLabel> adapter;
    adapter = new ArrayAdapter<Item.UnitLabel>(this.getActivity(), android.R.layout.simple_spinner_item,
            Item.UnitLabel.values());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    unitSpinner.setAdapter(adapter);

    EditText numStockBox = (EditText) view.findViewById(R.id.item_num_stock);
    numStockBox.setText("" + mItem.getNStock());

    // If this activity was started with the purpose of editing an existing
    // item, then we use the item passed in the intent to populate the
    // spinners and edit text boxes.
    if (!mItem.getName().equals("")) {
        // TODO Make non-focusable, non-touchable so it doesn't kick off the drop down.
        // But it doesn't work!
        nameBox.setFocusable(false);
        nameBox.setFocusableInTouchMode(false);
        nameBox.setText(mItem.getName());
        // Reset the focus & touch
        nameBox.setFocusable(true);
        nameBox.setFocusableInTouchMode(true);

        priceBox.setText(Float.toString(mItem.getPrice()));

        unitSpinner.setSelection(mItem.getUnitLabel().ordinal());
    }

    Button incrementNumStockButton = (Button) view.findViewById(R.id.item_increment_num_stock);
    incrementNumStockButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText et = (EditText) view.findViewById(R.id.item_num_stock);
            int numStock = getIntegerFromEditText(et);
            numStock++;
            et.setText(numStock + "");
        }
    });

    Button decrementNumStockButton = (Button) view.findViewById(R.id.item_decrement_num_stock);
    decrementNumStockButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText et = (EditText) view.findViewById(R.id.item_num_stock);
            int numStock = getIntegerFromEditText(et);
            numStock--;
            et.setText(numStock + "");
        }
    });

    Button saveButton = (Button) view.findViewById(R.id.item_save_button);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText et = (EditText) view.findViewById(R.id.item_name_box);
            String name = et.getText().toString();

            et = (EditText) view.findViewById(R.id.item_price_box);
            float price = getFloatFromEditText(et);

            et = (EditText) view.findViewById(R.id.item_unit_size_box);
            float size = getFloatFromEditText(et);

            Spinner spinner = (Spinner) view.findViewById(R.id.item_unit_label_spinner);
            int unitIndex = spinner.getSelectedItemPosition();

            et = (EditText) view.findViewById(R.id.item_num_stock);
            int numStock = getIntegerFromEditText(et);

            mItem = new Item(mItem.getId(), mItem.getListId(), name, numStock, mItem.getNBuy(), price, size,
                    Item.UnitLabel.values()[unitIndex], mItem.isBought(), mItem.getStockIdx(),
                    mItem.getShopIdx());
            if (mMode == Mode.ADD) {
                ((ShoppingListActivity) getActivity()).addItem(mItem);
            } else if (mMode == Mode.EDIT) {
                ((ShoppingListActivity) getActivity()).updateItem(mItem);
            } else {
                // shouldn't get here.
            }
            dismiss();
        }
    });

    Button cancelButton = (Button) view.findViewById(R.id.item_cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    Button deleteButton = (Button) view.findViewById(R.id.item_delete_button);
    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMode == Mode.EDIT) {
                ConfirmDeleteItemDialogFragment df = new ConfirmDeleteItemDialogFragment();
                df.setItem(mItem);
                df.show(getActivity().getSupportFragmentManager(), "confirm");
            }
            // Otherwise, we are adding this item, so we don't need to
            // delete it.
            // TODO: Remove modes altogether once autocomplete works, since
            // every item here will exist and be beging added.
            // CONSIDER: at that point, I will need to make sure that items
            // that have a name only (from autocomplete) have been saved in
            // the DB
            // and have a unique ID so they can be deleted.
            dismiss();
        }
    });

    return view;
}

From source file:pl.wasat.smarthma.ui.frags.base.BaseCollectionDetailsFragment.java

@NonNull
private AutoCompleteTextView buildAutoCompleteTextView(Parameter param) {
    String[] AUTO_PHRASES = new String[] { "[]", "[,]", "{}", "{,}", "1", "}", "]", "," };
    AutoCompleteTextView autoTextView = new AutoCompleteTextView(getActivity());
    TableLayout.LayoutParams layoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.WRAP_CONTENT, 1f);
    layoutParams.setMargins(40, 10, 40, 10);
    autoTextView.setLayoutParams(layoutParams);
    autoTextView.setHint(String.format(getActivity().getString(R.string.set_), param.getName()));
    autoTextView.setHintTextColor(Color.GRAY);
    autoTextView.setBackgroundColor(Color.WHITE);
    autoTextView.setTextSize(14);/*from  w  ww . j a v  a 2s  . c o  m*/

    autoTextView = resolvePattern(autoTextView, param.getPattern());
    autoTextView.addTextChangedListener(new EditTextViewInputWatcher(param));
    autoTextView.setOnTouchListener(new EditTextViewInputWatcher(param));
    autoTextView.setOnFocusChangeListener(new EditTextViewInputWatcher(param));

    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_dropdown_item_1line, AUTO_PHRASES);
    autoTextView.setAdapter(adapter);
    return autoTextView;
}

From source file:com.terraremote.terrafieldreport.OpenGroundReport.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.open_ground_layout);
    ButterKnife.bind(this);

    loadSharedPreferences();/*  w  w  w  . j av a  2 s . c o m*/

    Typeface customTypeface = Typeface.createFromAsset(getAssets(), "Raleway-Medium.ttf");
    TextView open_ground_text_font = findViewById(R.id.open_ground_text);
    open_ground_text_font.setTypeface(customTypeface);

    //        final DecimalFormat df = new DecimalFormat("0.00000");
    // Grab the current date and update the string variable 'userSelectedDateGround' with its value.
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    showDate.setText(sdf.format(new Date()));
    submissionDate = sdf.format(new Date());

    // get the defined string array of field team names
    ArrayAdapter<String> enterNameAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.TerraFieldTeamNames));
    AutoCompleteTextView enterNameTextView = (AutoCompleteTextView) mName;
    //set adapter for the auto complete fields
    enterNameTextView.setAdapter(enterNameAdapter);
    // specify the minimum type of characters before drop-down list is shown
    enterNameTextView.setThreshold(1);
    // comma to separate the different names
    enterNameTextView.setAdapter(enterNameAdapter);

    // get the defined string array of field team names
    ArrayAdapter<String> fieldTeamNameAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.TerraFieldTeamNames));
    MultiAutoCompleteTextView fieldTeamNameTextView = mColleagues;
    //set adapter for the auto complete fields
    fieldTeamNameTextView.setAdapter(fieldTeamNameAdapter);
    // specify the minimum type of characters before drop-down list is shown
    fieldTeamNameTextView.setThreshold(1);
    // comma to separate the different names
    fieldTeamNameTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    // get the defined string array of helicopter color names
    ArrayAdapter<String> vehicleColorAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.vehicle_colors));
    AutoCompleteTextView vehicleColorsTextView = (AutoCompleteTextView) mVehicleColour;
    //set adapter for the auto complete fields
    vehicleColorsTextView.setAdapter(vehicleColorAdapter);
    // specify the minimum type of characters before drop-down list is shown
    vehicleColorsTextView.setThreshold(1);
    // set adapter
    vehicleColorsTextView.setAdapter(vehicleColorAdapter);

    // get the defined string array of vehicle makes
    ArrayAdapter<String> vehicleMakeAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.vehicle_make));
    AutoCompleteTextView vehicleMakeTextView = (AutoCompleteTextView) mVehicleMake;
    //set adapter for the auto complete fields
    vehicleMakeTextView.setAdapter(vehicleMakeAdapter);
    // specify the minimum type of characters before drop-down list is shown
    vehicleMakeTextView.setThreshold(1);
    // set adapter
    vehicleMakeTextView.setAdapter(vehicleMakeAdapter);

    // get the defined string array of car rental agencies
    ArrayAdapter<String> rentalAgencyAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.rental_agencies));
    AutoCompleteTextView rentalAgencyTv = (AutoCompleteTextView) mRentalAgency;
    //set adapter for the auto complete fields
    rentalAgencyTv.setAdapter(rentalAgencyAdapter);
    // specify the minimum type of characters before drop-down list is shown
    rentalAgencyTv.setThreshold(1);
    // set adapter
    rentalAgencyTv.setAdapter(rentalAgencyAdapter);

    // get the defined string array of vehicle operator names
    ArrayAdapter<String> vehicleOperatorNameAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.check_in_contact_data_checker_names));
    AutoCompleteTextView vehicleOperatorNameTextView = (AutoCompleteTextView) mVehicleOperatorName;
    //set adapter for the auto complete fields
    vehicleOperatorNameTextView.setAdapter(vehicleOperatorNameAdapter);
    // specify the minimum type of characters before drop-down list is shown
    vehicleOperatorNameTextView.setThreshold(1);
    // set adapter
    vehicleOperatorNameTextView.setAdapter(vehicleOperatorNameAdapter);

}

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 ww. ja va2 s  .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/*www.  java 2s.  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:it.feio.android.omninotes.DetailFragment.java

private void displayLocationDialog() {
    PermissionsHelper.requestPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION,
            R.string.permission_coarse_location, snackBarPlaceholder,
            () -> GeocodeHelper.getLocation(new OnGeoUtilResultListener() {
                @Override//from   w  w w  .j  a  v  a2 s .c  om
                public void onAddressResolved(String address) {
                }

                @Override
                public void onCoordinatesResolved(Location location, String address) {
                }

                @Override
                public void onLocationUnavailable() {
                    mainActivity.showMessage(R.string.location_not_found, ONStyle.ALERT);
                }

                @Override
                public void onLocationRetrieved(Location location) {
                    if (location == null) {
                        return;
                    }
                    if (!ConnectionManager.internetAvailable(mainActivity)) {
                        noteTmp.setLatitude(location.getLatitude());
                        noteTmp.setLongitude(location.getLongitude());
                        onAddressResolved("");
                        return;
                    }
                    LayoutInflater inflater = mainActivity.getLayoutInflater();
                    View v = inflater.inflate(R.layout.dialog_location, null);
                    final AutoCompleteTextView autoCompView = (AutoCompleteTextView) v
                            .findViewById(R.id.auto_complete_location);
                    autoCompView.setHint(getString(R.string.search_location));
                    autoCompView.setAdapter(
                            new PlacesAutoCompleteAdapter(mainActivity, R.layout.simple_text_layout));
                    final MaterialDialog dialog = new MaterialDialog.Builder(mainActivity)
                            .customView(autoCompView, false).positiveText(R.string.use_current_location)
                            .callback(new MaterialDialog.ButtonCallback() {
                                @Override
                                public void onPositive(MaterialDialog materialDialog) {
                                    if (TextUtils.isEmpty(autoCompView.getText().toString())) {
                                        noteTmp.setLatitude(location.getLatitude());
                                        noteTmp.setLongitude(location.getLongitude());
                                        //                           GeocodeHelper.getAddressFromCoordinates(location, mFragment);
                                    } else {
                                        GeocodeHelper.getCoordinatesFromAddress(
                                                autoCompView.getText().toString(), mFragment);
                                    }
                                }
                            }).build();
                    autoCompView.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) {
                            if (s.length() != 0) {
                                dialog.setActionButton(DialogAction.POSITIVE, getString(R.string.confirm));
                            } else {
                                dialog.setActionButton(DialogAction.POSITIVE,
                                        getString(R.string.use_current_location));
                            }
                        }

                        @Override
                        public void afterTextChanged(Editable s) {
                        }
                    });
                    dialog.show();
                }
            }));
}