package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestTextView extends Activity {
public static final String TAG = TestTextView.class.getSimpleName();
private Button btn01;
private TextView tv01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview);
btn01 = (Button) findViewById(R.id.btn01);
tv01 = (TextView) findViewById(R.id.tv01);
btn01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv01.setText(R.string.change);
}
});
tv01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, tv01.getText() + "");
}
});
}
}
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ff888888"
>
<Button
android:id="@+id/btn01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="change text"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tv01"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="default"
/>
</ScrollView>
<!--
android:scrollHorizontally="true"
-->
</LinearLayout>