0

is there a way to handle long user inputs in alert dialogs? I have a small alert dialog that requires a few inputs and whenever the string input is too long, the other inputs and textviews get all squished up. Is there a way to put the string input on a different line or a way to wrap the other textfields? Im creating the alertdialog straight from code rather than XML.

    LinearLayout layout = new LinearLayout(this);
    EditText weight = new EditText(this);
    EditText mark = new EditText(this);
    TextView marktext = new TextView(this);
    marktext.setText("Mark");
    TextView weighttext = new TextView(this);
    weighttext.setText("Weight");
    mark.setInputType(InputType.TYPE_CLASS_NUMBER);
    weight.setInputType(InputType.TYPE_CLASS_NUMBER);

    //Assignment name input
    EditText workType = new EditText(this);
    workType.setInputType(InputType.TYPE_CLASS_TEXT);
    TextView workTypeText = new TextView(this);
    workTypeText.setText("Name of the work: ");

    weight.setId(99);
    mark.setId(100);
    workType.setId(9999);

    /*Spinner addworkspinner = new Spinner(this);
    ArrayAdapter<String> addworkadapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, ClassManager.possiblework);
    addworkspinner.setAdapter(addworkadapter); */
    layout.addView(workTypeText);
    layout.addView(workType);
    layout.addView(marktext);
    layout.addView(mark);
    layout.addView(weighttext);
    layout.addView(weight);

    AlertDialog.Builder addwork = new AlertDialog.Builder(this);
    addwork.setTitle("Add a piece of work");
    addwork.setView(layout);

1 Answers1

0

You may want to code a limit for your input text characters, wherein if it is over limit, it changes the nuumber of lines. Use (%) modulus to divide the number of characters in one certain line.

This information about Android: Vertical alignment for multi line EditText (Text area) may also help in identifying what you need to change in EditText.

Community
  • 1
  • 1
Franz Noel
  • 1,820
  • 2
  • 23
  • 50
  • yeah, i was thinking that but the problem is that even strings as small as 8 characters make it overflow – user3155915 May 19 '14 at 07:13
  • You can try putting a (-)dash after each a ,e ,i ,o ,u , y, or double letters such as 'll' and 'rr' if the word does not fit. Unless the string does not have vowels, y, 'rr', or 'll' in a certain line, we will have a problem. It may look like logi-\ncally, lo-\ngically, logical-\nly, and so on (where \n means end of line). – Franz Noel May 19 '14 at 07:24