Java Code Examples for android.widget.AutoCompleteTextView#addTextChangedListener()

The following examples show how to use android.widget.AutoCompleteTextView#addTextChangedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddSmsActivity.java    From SmsScheduler with GNU General Public License v2.0 6 votes vote down vote up
private void buildForm() {
    EditText formMessage = findViewById(R.id.form_input_message);
    AutoCompleteTextView formContact = findViewById(R.id.form_input_contact);
    TextWatcher watcherEmptiness = new EmptinessTextWatcher(this, formContact, formMessage);
    formContact.addTextChangedListener(watcherEmptiness);
    formMessage.addTextChangedListener(watcherEmptiness);

    new BuilderMessage().setView(formMessage).setSms(sms).build();
    new BuilderContact().setView(formContact).setSms(sms).setActivity(this).build();

    new BuilderSimCard().setActivity(this).setView(findViewById(R.id.form_sim_card)).setSms(sms).build();
    new BuilderRecurringMode()
        .setRecurringDayView((Spinner) findViewById(R.id.form_recurring_day))
        .setRecurringMonthView((Spinner) findViewById(R.id.form_recurring_month))
        .setDateView((DatePicker) findViewById(R.id.form_date))
        .setActivity(this)
        .setView(findViewById(R.id.form_recurring_mode))
        .setSms(sms)
        .build()
    ;

    new BuilderTime().setActivity(this).setView(findViewById(R.id.form_time)).setSms(sms).build();
    new BuilderDate().setActivity(this).setView(findViewById(R.id.form_date)).setSms(sms).build();

    new BuilderCancel().setView(findViewById(R.id.button_cancel)).setSms(sms).build();
}
 
Example 2
Source File: DropdownMenuEndIconDelegate.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onEditTextAttached(@NonNull TextInputLayout textInputLayout) {
  AutoCompleteTextView autoCompleteTextView =
      castAutoCompleteTextViewOrThrow(textInputLayout.getEditText());

  setPopupBackground(autoCompleteTextView);
  addRippleEffect(autoCompleteTextView);
  setUpDropdownShowHideBehavior(autoCompleteTextView);
  autoCompleteTextView.setThreshold(0);
  autoCompleteTextView.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
  autoCompleteTextView.addTextChangedListener(exposedDropdownEndIconTextWatcher);
  textInputLayout.setEndIconCheckable(true);
  textInputLayout.setErrorIconDrawable(null);
  textInputLayout.setTextInputAccessibilityDelegate(accessibilityDelegate);

  textInputLayout.setEndIconVisible(true);
}
 
Example 3
Source File: MainActivity.java    From android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	// Configura el adapter que enlazará los datos con el control Spinner
	ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, elementos);
	
	autoSpinner = (AutoCompleteTextView) findViewById(R.id.autospinner);
	// Añade el Listener al control Spinner (está definido en la propia clase)
	autoSpinner.addTextChangedListener(this);
	// Enlaza el adapter con el control Spinner
	autoSpinner.setAdapter(adapter);
	
	seleccion = (TextView) findViewById(R.id.seleccion);
}
 
Example 4
Source File: PoiKeywordSearchActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
/**
 * 设置页面监听
 */
private void setUpMap() {
	Button searButton = (Button) findViewById(R.id.searchButton);
	searButton.setOnClickListener(this);
	Button nextButton = (Button) findViewById(R.id.nextButton);
	nextButton.setOnClickListener(this);
	searchText = (AutoCompleteTextView) findViewById(R.id.keyWord);
	searchText.addTextChangedListener(this);// 添加文本输入框监听事件
	editCity = (EditText) findViewById(R.id.city);
	aMap.setOnMarkerClickListener(this);// 添加点击marker监听事件
	aMap.setInfoWindowAdapter(this);// 添加显示infowindow监听事件
}
 
Example 5
Source File: InputtipsActivity.java    From TraceByAmap with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_inputtip);
	minputlist = (ListView)findViewById(R.id.inputlist);
	mKeywordText = (AutoCompleteTextView)findViewById(R.id.input_edittext);
       mKeywordText.addTextChangedListener(this);
}
 
Example 6
Source File: EditSipUri.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
public EditSipUri(Context context, AttributeSet attrs) {
    super(context, attrs);
    setGravity(Gravity.CENTER_HORIZONTAL);
    setOrientation(VERTICAL);
    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.edit_sip_uri, this, true);

    dialUser = (AutoCompleteTextView) findViewById(R.id.dialtxt_user);
    accountChooserButtonText = (AccountChooserButton) findViewById(R.id.accountChooserButtonText);
    domainTextHelper = (TextView) findViewById(R.id.dialtxt_domain_helper);
    completeList = (ListView) findViewById(R.id.autoCompleteList);

    // Map events
    accountChooserButtonText.setOnAccountChangeListener(new OnAccountChangeListener() {
        @Override
        public void onChooseAccount(SipProfile account) {
            updateDialTextHelper();
            long accId = SipProfile.INVALID_ID;
            if (account != null) {
                accId = account.id;
            }
            if(contactsAdapter != null) {
                contactsAdapter.setSelectedAccount(accId);
            }
        }
    });
    dialUser.addTextChangedListener(this);
    
}
 
Example 7
Source File: AutoCompleteCityTextViewGenerator.java    From privacy-friendly-weather with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param editField    The component to "transform" into one that shows a city drop down list
 *                     based on the current input. Make sure to pass an initialized object,
 *                     else a java.lang.NullPointerException will be thrown.
 * @param listLimit    Determines how many items shall be shown in the drop down list at most.
 */
public void generate(AutoCompleteTextView editField, int listLimit, final int enterActionId, final MyConsumer<City> cityConsumer, final Runnable selectAction) {
    cityAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new ArrayList<City>());
    this.editField = editField;
    this.cityConsumer = cityConsumer;
    this.listLimit = listLimit;
    editField.setAdapter(cityAdapter);
    editField.addTextChangedListener(new TextChangeListener());

    editField.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedCity = (City) parent.getItemAtPosition(position);
            cityConsumer.accept(selectedCity);
        }
    });

    editField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == enterActionId) {
                Boolean checkCity = checkCity();
                if (checkCity) {
                    selectAction.run();
                }
                return true;
            }
            return false;
        }
    });
}
 
Example 8
Source File: FloatingLabelAutoCompleteTextView.java    From android-floatinglabel-widgets with Apache License 2.0 5 votes vote down vote up
@Override
protected void afterLayoutInflated(Context context, AttributeSet attrs, int defStyle) {
    super.afterLayoutInflated(context, attrs, defStyle);

    final CharSequence completionHint;
    final int completionThreshold;
    final int popupBackground;
    final int dropDownWidth;
    final int dropDownHeight;

    if (attrs == null) {
        completionHint = "";
        completionThreshold = 1;
        dropDownHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
        dropDownWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
        popupBackground = getDefaultPopupBackgroundResId();
    } else {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingLabelAutoCompleteTextView, defStyle, 0);
        completionHint = a.getText(R.styleable.FloatingLabelAutoCompleteTextView_android_completionHint);
        completionThreshold = a.getInt(R.styleable.FloatingLabelAutoCompleteTextView_android_completionThreshold, 1);
        dropDownHeight = a.getDimensionPixelSize(R.styleable.FloatingLabelAutoCompleteTextView_android_dropDownHeight, ViewGroup.LayoutParams.WRAP_CONTENT);
        dropDownWidth = a.getDimensionPixelSize(R.styleable.FloatingLabelAutoCompleteTextView_android_dropDownWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupBackground = a.getResourceId(R.styleable.FloatingLabelAutoCompleteTextView_android_popupBackground, getDefaultPopupBackgroundResId());
        a.recycle();
    }

    final AutoCompleteTextView inputWidget = getInputWidget();
    inputWidget.setCompletionHint(completionHint);
    inputWidget.setThreshold(completionThreshold);
    inputWidget.setDropDownWidth(dropDownWidth);
    inputWidget.setDropDownHeight(dropDownHeight);
    inputWidget.setDropDownBackgroundResource(popupBackground);
    inputWidget.addTextChangedListener(new EditTextWatcher());
}
 
Example 9
Source File: Main.java    From iZhihu with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
    mAutoCompleteTextView = (AutoCompleteTextView) menuItem.getActionView().findViewById(R.id.search);

    questionsAdapter = new QuestionsAdapter(this, searchedQuestions);
    questionsAdapter.setHideDescription(true); // Hide Description

    mAutoCompleteTextView.addTextChangedListener(textWatcher);
    mAutoCompleteTextView.setAdapter(questionsAdapter);
    mAutoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Helper.startDetailActivity(Main.this, searchedQuestions, i);
        }
    });

    // Request focus.
    mAutoCompleteTextView.requestFocus();
    (new Timer()).schedule(
            new TimerTask() {
                @Override
                public void run() {
                    mInputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                }
            }, 10
    );
    return true;
}
 
Example 10
Source File: AddItemShoppingList.java    From ShoppingList with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_add_item_shopping_list);

	try {
		shoppingList = ShoppingListDAO.select(this, getIntent().getExtras().getInt((getString(R.string.id_shopping_list))));
	} catch (VansException e) {
		Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
		e.printStackTrace();
	}

	this.setTitle(shoppingList.getName());

	lvItensShoppingList = (ListView) findViewById(R.id.lvItemShoppingList);
	lvItensShoppingList.setOnItemClickListener(this);
	lvItensShoppingList.setOnItemLongClickListener(this);

	headerView = (View) getLayoutInflater().inflate(R.layout.header_list_view_item_shopping_list, null);
	lvItensShoppingList.addHeaderView(headerView, null, false);

	adapter = new ItemShoppingListCursorAdapter(this, shoppingList.getId());
	lvItensShoppingList.setAdapter(adapter);

	edUnitValue = (EditText) findViewById(R.id.edUnitValue);
	edUnitValue.setVisibility(UserPreferences.getShowUnitValue(this) ? View.VISIBLE : View.GONE);
	edUnitValue.setOnKeyListener(this);
	edUnitValue.addTextChangedListener(new CustomEditTextWatcher(edUnitValue, 5));
	edUnitValue.setOnFocusChangeListener(this);

	edQuantity = (EditText) findViewById(R.id.edQuantity);
	edQuantity.addTextChangedListener(new CustomEditTextWatcher(edQuantity, 4));
	edQuantity.setVisibility(UserPreferences.getShowQuantity(this) ? View.VISIBLE : View.GONE);
	edQuantity.setOnFocusChangeListener(this);

	edDescription = (AutoCompleteTextView) findViewById(R.id.edDescription);
	edDescription.setOnItemClickListener(this);
	edDescription.addTextChangedListener(new CustomEditTextWatcher(edDescription, -1));

	if ((!UserPreferences.getShowQuantity(this)) && (!UserPreferences.getShowUnitValue(this))) {
		edDescription.setImeOptions(EditorInfo.IME_ACTION_GO);
		edDescription.setOnKeyListener(this);
	} else if (!UserPreferences.getShowUnitValue(this)) {
		edQuantity.setImeOptions(EditorInfo.IME_ACTION_GO);
		edQuantity.setOnKeyListener(this);
	}

}
 
Example 11
Source File: AutoCompleteRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public View getView(View convertView) {
    View view;
    AutoCompleteRowHolder holder;

    // List<String> options = optionset.getOptions();

    if (convertView == null) {
        ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.listview_row_autocomplete, null);

        TextView textLabel = (TextView)
                rootView.findViewById(R.id.text_label);
        AutoCompleteTextView autoComplete = (AutoCompleteTextView)
                rootView.findViewById(R.id.chooseOption);
        AutoCompleteEditTextWatcher textWatcher = new AutoCompleteEditTextWatcher(field);

        autoComplete.addTextChangedListener(textWatcher);

        ImageView showOptions = (ImageView) rootView.findViewById(R.id.showDropDownList);
        DropDownButtonListener listener = new DropDownButtonListener(autoComplete);
        showOptions.setOnClickListener(listener);

        holder = new AutoCompleteRowHolder(textLabel, autoComplete, showOptions,
                listener, textWatcher);

        rootView.setTag(holder);
        view = rootView;
    } else {
        view = convertView;
        holder = (AutoCompleteRowHolder) view.getTag();
    }
    RowCosmetics.setTextLabel(field, holder.textLabel);


    loadOptions();

    String name;
    if (mCodeToNameMap.containsKey(field.getValue())) {
        name = mCodeToNameMap.get(field.getValue());
    } else {
        name = EMPTY_FIELD;
    }
    holder.textWatcher.setOptions(mNameToCodeMap);
    holder.textWatcher.setField(field);
    holder.autoComplete.setText(name);
    holder.autoComplete.setAdapter(adapter);
    holder.autoComplete.addTextChangedListener(holder.textWatcher);

    holder.listener.setAutoComplete(holder.autoComplete);
    holder.button.setOnClickListener(holder.listener);
    holder.autoComplete.clearFocus();
    holder.autoComplete.setOnEditorActionListener(mOnEditorActionListener);
    if(readOnly){
        holder.button.setEnabled(false);
        holder.autoComplete.setEnabled(false);
    } else {
        holder.button.setEnabled(true);
        holder.autoComplete.setEnabled(true);
    }
    return view;
}