Pranit Bankar
Pranit Bankar

Reputation: 473

What is the difference between View arg0 and View v?

I wrote an xml file for my code and it has 2 buttons. However, the buttons in java file by default showed this.

BCel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        output=(input-32)*5/9;  
    }
});
BFah.setOnClickListener(new View.OnClickListener() {    
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        output=1.8*input+32;
    }
});

(output=... is obviously written by me)

What I don't understand is why does it show arg0 in the first one and v in the second one. The other similar questions ask why does it show arg0, arg1, ar2 etc. but I fail to understand this variety.

Will this cause any error in my application ?

Upvotes: 1

Views: 5804

Answers (4)

aioobe
aioobe

Reputation: 421150

The arg0 and v are just variable names. You could choose any valid Java identifier.

What I don't understand is why does it show arg0 in the first one and v in the second one.

If you, in Eclipse, choose the option "Override method in OnClickListener" or let Eclipse fill in the methods in an anonymous class it will automatically select the same variable name as the overridden methods (and argN if the source code is not attached).

Will this cause any error in my application ?

No, as long as you stick with valid Java identifiers it won't cause any errors.

Upvotes: 2

PPD
PPD

Reputation: 5900

You can use any name for variable it does not matter.You are getting error because input is undefined symbol. You have to declare it before using it.

Upvotes: 0

MSR
MSR

Reputation: 533

There is no any difference between arg0 and v . both are just identifier may be you got error due to this Statement

  output=1.8*input+32;

may be casting error etc depending on data type of "input"

Upvotes: 0

mkobit
mkobit

Reputation: 47289

Having different names will not cause an error in your application. They are the names of your parameters for those methods. It is most likely just Eclipse auto-generating a parameter name when you instantiate the anonymous class using new View.OnClickListener() {...}, but you could use any valid Java identifier.

Upvotes: 0

Related Questions