Skip to content

Instantly share code, notes, and snippets.

@jezinka
Last active March 20, 2017 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/432c3ea3cac16b93dc6c0b343f9219b7 to your computer and use it in GitHub Desktop.
Save jezinka/432c3ea3cac16b93dc6c0b343f9219b7 to your computer and use it in GitHub Desktop.
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