3
我在聊天應用程序工作。 每當我提交或接收短信時,我都會將它們附加到聊天室。 當列表變長時,我需要向下滾動才能看到它們。 如何使它自動滾動到新添加的文本?如何在textview上顯示最新的附加文本?
<ScrollView
android:id="@+id/scrollView01"
android:layout_width="fill_parent"
android:layout_height="100px" >
<TextView
android:id="@+id/txtChat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
</ScrollView>
//
SendMsg.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String name = txtName.getText().toString();
String message = txtMessage.getText().toString();
if (message.length() > 0) {
sendMsg(name, message);
String myMessage = message + "\n";
tvChat.append(myMessage);
}
else
Toast.makeText(getBaseContext(),
"Please enter both name and message.", Toast.LENGTH_SHORT).show();
}
});
和Don」忘記 - > mChatBox =(ScrollView)findViewById(R.id.scrollView); – conandor 2010-09-10 13:19:24
就像其他的Android元素:)這就是爲什麼我沒有指定它,但感謝發佈它,也許它有助於某人。 – Maragues 2010-09-13 06:45:28