【问题标题】:User input too long for alertdialog to handle用户输入太长,警报对话框无法处理
【发布时间】:2014-07-07 01:08:07
【问题描述】:

有没有办法处理警报对话框中的长用户输入?我有一个小的警报对话框,需要一些输入,每当字符串输入太长时,其他输入和文本视图都会被压扁。有没有办法将字符串输入放在不同的行或包装其他文本字段的方法?我直接从代码而不是 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);

【问题讨论】:

    标签: java android android-alertdialog


    【解决方案1】:

    您可能想为输入的文本字符设置一个限制,如果超出限制,它会更改行数。使用 (%) 模数除以某一行的字符数。

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

    【讨论】:

    • 是的,我在想,但问题是即使是小到 8 个字符的字符串也会溢出
    • 如果单词不合适,您可以尝试在每个 a 、e 、i 、o 、u 、y 或双字母(例如 'll' 和 'rr' )后面加上 (-) 破折号。除非字符串在某一行中没有元音、y、'rr' 或 'll',否则我们就会遇到问题。它可能看起来像 logi-\ncally、lo-\ngically、logical-\nly 等等(其中 \n 表示行尾)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多