• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Object Properties

oosgearoo

Newbie
[HIGH] @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//button1 =(Button) findViewById(R.id.button1);
//button1.Text ="But";
v.Text ="test"
self.Text="I was clicked";
}[/HIGH]

Here is another small problem along the lines of hello world.
In windows/pascal I would say button1.caption:="someText";
If the test is the button click how does one set its own caption(button) to reflect that click. I keep getting text is not an field or item or something similar.

How to refer to and Object(Buttons)fields???

Away from home and dont have the option off watching videos to work this out.
 
The usual way in Java is to call getter and setter methods. eg.

[HIGH]public class MyClass {

private String url = "";

public String getUrl(){
return url;
}

public void setUrl(String url){
this.url = url;
}

}
[/HIGH]url can be accessed within MyClass but as it is private, it can't be accessed from anywhere else. If you wanted to use MyClass

[HIGH] MyClass myClass = new MyClass();
//Set url
myClass.setUrl("www.example.com");
//Get url
String myUrl = myClass.getUrl();
[/HIGH]

It is usual to prefix these methods with get and set. In Android to set the text of a textTview, the method you want is setText(),
 
Just a qualification to my "it can't be accessed from anywhere else" above. It is actually possible using reflection but that's not something you would usually want to do.

Hmm I got it to work by the way, I new about settext but it would not compile, it eventually added a "Finale" statement to the button variable declaration then the settext bit compiled. Now that's what I call hard
programing the code is right you know its right but it wont compile till you add something somewhere else annoying.

On a side note Iam away from home on holiday in Glasgow, I ve bought two books one on Android programing and the other on Java so between the two I may actualy start getting someplace.

Global variables are not a good idea I was told when I learn 't pascal.
Iam passed v as a variable would that be of button origin? I understand
everything is a view in Java but in button click will it be button passed in the onClick call? v.setText("hello"); ??

Thanks for getting back to be jonbanjo your help is very much appreciated Ive started trying to help a few out to in the forums leaving the hard stuff to the pro's

Thanks again
 
I think you'll find the book on Java useful. I'm new to Android (say May this year) but I did know a bit of Java and it has helped - most of my own wrestles have been with Android specific bits.
 
Back
Top Bottom