用户输入太长,无法处理alertdialog

时间:2014-05-19 06:59:43

标签: java android android-alertdialog

有没有办法在警报对话框中处理长用户输入?我有一个小的警告对话框,需要一些输入,每当字符串输入太长时,其他输入和文本视图都会被压缩。有没有办法将字符串输入放在不同的行或包装其他文本字段的方式?我直接从代码而不是XML创建alertdialog。

    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 个答案:

答案 0 :(得分:0)

您可能希望为输入文本字符编码限制,如果超出限制,则会更改行数。使用(%)模数来划分某一行中的字符数。

此信息 Android: Vertical alignment for multi line EditText (Text area)也可能有助于确定您在EditText中需要更改的内容。