Dhaval Shah
Dhaval Shah

Reputation: 698

In an Android ,I am a beginner.I write this code; public void Showmsg(View v)

I write the following code in MainActivity.java.This code is about on the click of the button. Suppose There is a default text "dhaval" But when I click on the button 'WELCOME' the text shoud be changed like "Hi!This is Dhaval's First App".So I write the onClick of the button the function public void Showmsg()

In this I can't understand why we pass 'View object' as a parameter?

Following code I written:

 public void Showmsg(View v)
    {
        TextView tv =(TextView) findViewById(R.id.textView1);
        tv.setText("Hi!This is Dhaval's First App");
    }

Upvotes: 0

Views: 71

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83527

Every onClick method must have a View parameter. This is a reference to the view which was clicked.

Upvotes: 1

Related Questions