Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created May 9, 2017
Embed
What would you like to do?
filterEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Drawable drawable = filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT];
if (drawable != null) {
Rect bounds = drawable.getBounds();
if (event.getRawX() >= (filterEditText.getRight() - bounds.width())) {
String text = filterEditText.getText().toString().trim();
if (text.length() != 0) {
long ingredientId = ingredientContract.insert(dbHelper, text);
mealIngredientContract.insert(dbHelper, meal.getId(), ingredientId);
ingredientListAdapter.updateResults(mealIngredientContract.getIngredientsWithMeal(meal, dbHelper));
filterEditText.setText("");
Toast.makeText(v.getContext(), R.string.ingredient_added_message, Toast.LENGTH_SHORT).show();
return true;
}
}
}
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment