Saturday, 19 January 2013

Working with TextView

Screen Shots:






1.main.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:background="#EEA9B8"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="120dp"
        android:gravity="center"
        android:text="TextView"
        android:textColor="#ffffff"
        android:textSize="25dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18dp"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:text="Change Text" />

</LinearLayout>


2.Activity:


package com.venky.textview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TextViewActivity extends Activity {
    /** Called when the activity is first created. */

    TextView textview;
    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);

         textview = (TextView) findViewById(R.id.textview);

         button = (Button) findViewById(R.id.button);
         button.setOnClickListener(new OnClickListener() {

             public void onClick(View v) {
                  // TODO Auto-generated method stub

                  textview.setText("Text Changed");
             }
         });
    }
}


3)Download this Project Click Here

 

1 comment: