project name: Textview
Android version: 1.5 (support 1.5 and above versions)
<?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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:text="This is TextView" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF4500"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Large Text"
android:textColor="#FFD700"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF4500"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Medium Text"
android:textColor="#8B0000"
android:textAppearance="?android:attr/textAppearanceMedium" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF4500"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Small Text"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceSmall" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF4500"/>
<Button
android:id="@+id/button1"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View String" />
<Button
android:id="@+id/button2"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View number" />
<Button
android:id="@+id/button3"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View Long number" />
<Button
android:id="@+id/button4"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View Float number" />
<Button
android:id="@+id/button5"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View Double number" />
<Button
android:id="@+id/button6"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View char" />
<Button
android:id="@+id/button7"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="View char array" />
</LinearLayout>
TextviewActivity.java
OUTPUT:
click View String button
Click View Long number button
Click View double number button
package selva.text;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TextviewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button viewstring=(Button) findViewById(R.id.button1);
Button viewno=(Button) findViewById(R.id.button2);
Button viewlongno=(Button) findViewById(R.id.button3);
Button viewfloatno=(Button) findViewById(R.id.button4);
Button viewdoubleno=(Button) findViewById(R.id.button5);
Button viewchar=(Button) findViewById(R.id.button6);
Button viewchararray=(Button) findViewById(R.id.button7);
final TextView textview=(TextView) findViewById(R.id.textView1);
final TextView ltextview=(TextView) findViewById(R.id.textView2);
final TextView mtextview=(TextView) findViewById(R.id.textView3);
final TextView stextview=(TextView) findViewById(R.id.textView4);
viewstring.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String st="Textview String";
textview.setText(st);
String st1="Large Textview String";
ltextview.setText(st1);
String st2="Medium Textview String";
mtextview.setText(st2);
String st3="Small Textview String";
ltextview.setText(st3);
}
});
viewno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int i,i1,i2,i3;
i=111;
String st=String.valueOf(i);
textview.setText(st);
i1=222;
String st1=String.valueOf(i1);
ltextview.setText(st1);
i2=333;
String st2=String.valueOf(i2);
mtextview.setText(st2);
i3=444;
String st3=String.valueOf(i3);
stextview.setText(st3);
}
});
viewlongno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
long i,i1,i2,i3;
i=11111111111111L;
String st=String.valueOf(i);
textview.setText(st);
i1=22222222222222L;
String st1=String.valueOf(i1);
ltextview.setText(st1);
i2=33333333333333L;
String st2=String.valueOf(i2);
mtextview.setText(st2);
i3=4444444444444L;
String st3=String.valueOf(i3);
stextview.setText(st3);
}
});
viewfloatno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
float i,i1,i2,i3;
i=111.101F;
String st=String.valueOf(i);
textview.setText(st);
i1=222.202F;
String st1=String.valueOf(i1);
ltextview.setText(st1);
i2=333.303f;
String st2=String.valueOf(i2);
mtextview.setText(st2);
i3=444;
String st3=String.valueOf(i3);
stextview.setText(st3);
}
});
viewdoubleno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double i,i1,i2,i3;
i=111.101;
String st=String.valueOf(i);
textview.setText(st);
i1=222;
String st1=String.valueOf(i1);
ltextview.setText(st1);
i2=333.303D;
String st2=String.valueOf(i2);
mtextview.setText(st2);
i3=444.404F;
String st3=String.valueOf(i3);
stextview.setText(st3);
}
});
viewchar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
char ch='s';
String st=String.valueOf(ch);
textview.setText(st);
char ch1='m';
String st1=String.valueOf(ch1);
ltextview.setText(st1);
char ch2='p';
String st2=String.valueOf(ch2);
mtextview.setText(st2);
char ch3='n';
String st3=String.valueOf(ch3);
stextview.setText(st3);
}
});
viewchararray.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
char ch[]={'s','s'};
String st=String.valueOf(ch);
textview.setText(st);
char ch1[]={'m','m'};
String st1=String.valueOf(ch1);
ltextview.setText(st1);
char ch2[]={'p','p'};
String st2=String.valueOf(ch2);
mtextview.setText(st2);
char ch3[]={'n','n'};
String st3=String.valueOf(ch3);
stextview.setText(st3);
}
});
}
}
click View String button
Click View number button
Click View Long number button
Click View Float number button
Click View double number button