Skip to content

Instantly share code, notes, and snippets.

@jezinka
Last active Mar 20, 2017
Embed
What would you like to do?
Button button = (Button) findViewById(R.id.addMealButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setTitle(R.string.putMealName);
final EditText input = new EditText(v.getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
builder.setView(input);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mealName = input.getText().toString();
MealContract meal = new MealContract();
meal.insertMeal(builder.getContext(), mealName);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment