我有這樣的代碼:EditText.getText具有延遲
void sendMessage(){
EditText messageText = (EditText) findViewById(R.id.editText3);
String messageString = messageText.getText().toString();
LinearLayout chatLayout = (LinearLayout) findViewById(R.id.chatView);
TextView chatMessage = new TextView(this);
chatMessage.setText(messageString);
chatLayout.addView(chatMessage);
messageText.setText("");
scrollChatDown();
/*
int arraySize = messages.size();
messages.set(arraySize + 1, chatMessage);
*/
}
當我調用函數SendMessage();通過一個按鈕,它給出了一個空的TextView,當我再次調用該函數時,它給了我一個帶有文本的TextView。
輸出
我做了什麼jiotman所說的,但它沒有工作,現在我有這個
void sendMessage(){
TextView chatMessage = new TextView(this);
EditText messageText = (EditText) findViewById(R.id.editText3);
String messageString = messageText.getText().toString();
LinearLayout chatLayout = (LinearLayout) findViewById(R.id.chatView);
chatLayout.addView(chatMessage);
chatMessage.setText(messageString);
messageText.setText("");
scrollChatDown();
/*
int arraySize = messages.size();
messages.set(arraySize + 1, chatMessage);
*/
}
發佈一點點的代碼吧,請 –