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

The following examples show how to use android.widget.AutoCompleteTextView#setOnKeyListener() . 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: MainActivity.java    From android-app with GNU General Public License v2.0 5 votes vote down vote up
private void setupSearch() {

        search = (AutoCompleteTextView) findViewById(R.id.search);
        //Quando o usuario digita enter, ele faz a requisição procurando a posição daquela linha
        search.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                String searchContent = search.getText().toString();
                Activity activity = MainActivity.this;

                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                        (keyCode == KeyEvent.KEYCODE_ENTER) &&
                        Util.isValidString(searchContent)) {

                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(search.getWindowToken(), 0);

                    if (NetworkUtil.checkInternetConnection(activity)) {

                        new BusSearchTask(MainActivity.this).execute(searchContent);

                    } else {
                        Toast.makeText(activity, getString(R.string.error_connection_internet), Toast.LENGTH_SHORT).show();
                    }
                    return true;
                }
                return false;
            }
        });
    }
 
Example 2
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);
	}

}