开发者_运维知识库
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this questionI am working my way through the tutorials at Android Developers, and have come across a question that I am sure truly shows my newbie status. In step 2 of 'Radio Buttons' in the HelloFormStuff section of the HelloViews tutorial, I am directed to "add the following code to create a new member in the HelloFormStuff Activity: " ... What does that mean?
Do i add another class to the package? (new class dialog in eclipse grays out option for private class) Do I insert somewhere inside the class HelloFormStuff? (error given: "Illegal modifier for parameter radio_listener; only final is permitted" Thank you for any help you may provide.The radio_listener
is the new member. A member is like a part of the the class.
So pasting the provided code into the class is actually creating the new member.
It will look something like this (not tested, just read it as "pseudocode" please :) )
class HelloFormStuff extends Activity{
//other stuff
private OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
};
//other stuff, like onCreate();
}
精彩评论