How To Change TextView On Click Event – Android TextView Example

How To Change TextView On Click Event – Android TextView Example

How To Change TextView On Click Event – Android TextView Example

access_time September 5, 2017 chat_bubble_outline 0 comments

TextView is a widget in android to show Text in the formatted and unformatted text.Here in the tutorial, we are going learn about changing the TextView on click events of a button.

TextView Example

TextView Example

Step 1: Open up a project and name it as you like here in this tutorial I am naming it example.Drag and Drop TextView and Button from Widgets from the palette or this XML code for design part.

Step 2: Create an object of TextView and Button and type cast it to TextView and Button respectively.Make OnClickListener for the button as shown.

Step 3: Call SetText method by using TextView object which you declared in Step:1.

Decode The Code: Here we are changing the TextView when Button is clicked.Initial, we made TextView and Button in designing part in the XML  or it can be made by using drag and drop.Next, we declared an object of Textiew and Button in the MainActivity.java file.We made an OnclickListener for Button using object of a button.Lastly, we have set the text to TextView using object of TextView by calling SetText() method.

content_copyCategorized under

No Comments

comment No comments yet

You can be first to leave a comment

Submit an answer

<