Hello all,
I came across the vintage thermometer code from Ivan Memruk
(mindtherobot) and decided to use it to learn from. If you would
take a look at it,
http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/
it and follow along I have a problem I don't understand as of yet.
You see I used his code and built the project, added in the code from
Orn Kristjansson (post #39) to randomly seed the value for the
setHandTarget() method. That works just fine. Now I wanted to expand
my understanding and take the custom view (not defined as an inner
class) and interact with it by way of a Button (actually two, like
Move, and Reset) with an EditText. I wanted to take the value in the
EditText and send it as an argument to the SetHandTarget() method.
So essentially allowing the user to call setHandTarget(50) and then
watch as the invalidate() method redraws the custom view with the
needle moving to the newly entered location.
setHandTarget() is a private void "instance" method within the
thermometer class (extends view). I don't understand how to properly
prefix it with (some object) to allow me to call it from the
thermometerActivity class (extendeds activity).
So here's some code I added to the thermometerActivity:
//==============================================================
CalculateButton
//====Define a calculate button and it's handler
//====Grab hold of the instance of our button
Button calcButton = (Button) findViewById(R.id.calculate);
//==============================================================
instantiate ButtonHandler and Listener
//====set the Callback
calcButton.setOnClickListener(new calcButtonHandler());
//===========================================================
private class calcButtonHandler implements OnClickListener{
@Override
public void onClick(View v) {
//====
//==== I though since it's in the same package I could call is by
it's ParetClass.method()
//==== but it is not a static method so this will not
work
//Thermometer.setHandDTarget( (float)(76) );
//==== So I thought, I'll import the public class
(Thermometer) and change the method to public
//==== an try calling it
//setHandTarget((float) (76));
//==== but that didn't work either
//==== So if calcButtonHandler is a private inner
class of ThermometerActivity
//==== can I call the setHandTarget() method from the
public class Thermometer
}
}
Useful resources (not specific to Android):
http://www.leepoint.net/notes-java/index.html
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en