Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Here's my code (that creates the first, 'Create Tag', dialog):
final Dao<Tag, Integer> tagDao = getHelper().getTagDao();
final EditText input = new EditText(this);
input.setSingleLine(true);
input.setHint(R.string.create_tag_dialog_hint);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(input);
builder.setTitle(getString(R.string.create_tag_dialog_title));
builder.setPositiveButton(
getString(R.string.create_tag_dialog_positive),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString().trim();
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
Tag tag = new Tag(value);
try {
tagDao.create(tag);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
builder.setNegativeButton(
getString(R.string.create_tag_dialog_negative), null);
builder.show();
Sorry for the length of the post and thanks for any helpful comments.
Just sorted this myself. Using an instance of AlertDialog, you can specify setView and pass in spacing parameters. This will work.
final EditText input = new EditText(this);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setView(input, 10, 0, 10, 0); // 10 spacing, left and right
alertDialog.setButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Clicked
alertDialog.show();
Edit: I'm aware this question is old, but no solution was provided.
–
–
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
final EditText input = new EditText(this);
input.setSingleLine(true);
layout.setPadding(10, 0, 10, 0);
input.setHint("Hint");
layout.addView(input);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
Moreover, setSingleLine is deprecated. You should use InputStyle.
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.