Android Textview

Android Development

Android Textview :-

⇛ .xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".First"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">

<!--Its a first Textview-->

<TextView

android:id="@+id/Idtextview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Q: What is your name ?"
android:textStyle="italic"
android:textAllCaps="false"
android:textColor="#05cc0c"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textIsSelectable="true"
android:textColorHint="#beb0af"/>

<!--Its a second Textview-->

<TextView

android:id="@+id/Idtextview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A: My name is Dhiraj Baidya ."
android:textStyle="bold"
android:textAllCaps="false"
android:textColor="#c40623"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textIsSelectable="true"
android:textColorHint="#beb0af"/>

<!--Its a third Textview-->

<TextView

android:id="@+id/Idtextview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Q: What class do you read in ?"
android:textStyle="italic"
android:textAllCaps="false"
android:textColor="#05cc0c"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textIsSelectable="true"
android:textColorHint="#beb0af"/>

<!--Its a four Textview-->

<TextView

android:id="@+id/Idtextview4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A: I read in class twelve ."
android:textStyle="bold"
android:textAllCaps="false"
android:textColor="#c40623"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textIsSelectable="true"
android:textColorHint="#beb0af"/>

<!--Its a five Textview-->

<TextView

android:id="@+id/Idtextview5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Q: What are you doing now ?"
android:textStyle="italic"
android:textAllCaps="false"
android:textColor="#05cc0c"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textIsSelectable="true"
android:textColorHint="#beb0af"/>

<!--Its a six Textview-->

<TextView

android:id="@+id/Idtextview6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A: Now i learn Android ."
android:textStyle="bold"
android:textAllCaps="false"
android:textColor="#c40623"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textIsSelectable="true"
android:textColorHint="#beb0af"/>

<!--Its a seven Textview-->

<TextView

android:id="@+id/Idtextview7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Q: What is Java ?"
android:textStyle="italic"
android:textSize="20sp"
android:textAllCaps="false"
android:textColor="#05cc0c"
android:textIsSelectable="true"
android:layout_marginLeft="20dp"
android:textColorHint="#beb0af"/>

<!--Its a seven Textview-->

<TextView

android:id="@+id/Idtextview8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A: Java is Object Oriented Programming language."
android:textStyle="bold"
android:textSize="20sp"
android:textAllCaps="false"
android:textColor="#c40623"
android:textIsSelectable="true"
android:layout_marginLeft="20dp"
android:textColorHint="#beb0af"/>

</LinearLayout>
⇛ java file :
package com.example.dell.textview;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class First extends AppCompatActivity {

//Here is variable in this Textview.

private TextView txt1, txt2, txt3, txt4, txt5, txt6, txt7, txt8;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);

txt1 = (TextView) findViewById(R.id.Idtextview1);

txt2 = (TextView) findViewById(R.id.Idtextview2);

txt3 = (TextView) findViewById(R.id.Idtextview3);

txt4 = (TextView) findViewById(R.id.Idtextview4);

txt5 = (TextView) findViewById(R.id.Idtextview5);

txt6 = (TextView) findViewById(R.id.Idtextview6);

txt7 = (TextView) findViewById(R.id.Idtextview7);

txt8 = (TextView) findViewById(R.id.Idtextview8);

//onClick Listener will fire whan click on any Textview.

txt1.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's TextView 1",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt1.setText("You Clicked the TextView 1");
* #set the text after clicking button.#*/
}

});

txt2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's TextView 2",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt2.setText("You Clicked the TextView 2");
* #set the text after clicking button.#*/
}

});

txt3.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's TextView 3",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt3.setText("You Clicked the TextView 3");
* #set the text after clicking button.#*/
}

});

txt4.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's TextView 4",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt4.setText("You Clicked the TextView 4");
* #set the text after clicking button.#*/
}

});

txt5.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's TextView 5",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt5.setText("You Clicked the TextView 5");
* #set the text after clicking button.#*/
}

});

txt6.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's TextView 6",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt6.setText("You Clicked the TextView 6");
* #set the text after clicking button.#*/
}

});

txt7.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's a Textview 7",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt7.setText("You Clicked the TextView 7");
* #set the text after clicking button.#*/
}

});

txt8.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(),"Hey! it's a Textview 8",Toast.LENGTH_SHORT).show();

/*If you don't know What is Toast You Use this...

* txt8.setText("You Clicked the TextView 8");
* #set the text after clicking button.#*/
}

});
}
}

No comments

Powered by Blogger.