2014-05-19 54 views
0

有沒有辦法處理警報對話框中長時間的用戶輸入?我有一個小小的提醒對話框,需要幾個輸入,並且每當字符串輸入太長時,其他輸入和文本瀏覽都會被擠掉。有沒有辦法將字符串輸入放在不同的行上或包裝其他文本框的方式?我直接從代碼而不是XML創建alertdialog。用戶輸入太長,無法處理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); 

回答

0

您可能希望將代碼爲您輸入的文本字符的限制,其中,若超過上限,它改變線的nuumber。使用(%)模數來劃分某一行中的字符數。

有關 Android: Vertical alignment for multi line EditText (Text area)的信息也可能有助於確定您需要在EditText中進行更改。

+0

是的,我在想,但問題是,即使是小到8個字符的字符串使其溢出 – user3155915

+0

您可以嘗試在每個a,e,i,o,u,y或double之後加上( - )短劃線如果單詞不合適,則會顯示'll'和'rr'等字母。除非字符串在特定行中沒有元音,y,'rr'或'll',否則我們會遇到問題。它可能看起來像邏輯,邏輯,邏輯,\ nly等等(其中\ n表示行結束)。 –