I'm writing a simple app for my Bday to see how many people will come.

I need to assign an action to the button when every time I press it, it adds 1 to the final number of guests. Button id is: "Button" Final number of guests id is: "Number"

Could someone help me with the script for Eclipse? I know it is easy but I am stuck.

有帮助吗?

解决方案

It's just incrementing a local variable? If the button is declared in the Activity, just do this:

public class MainActivity extends Activity {

private Button button;

@Override
onCreate(){
    super.onCreate();
    button = ( Button ) findViewById( R.id.Button );

    button.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick( View v ) {
            Number++;
        }
    } );

}
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top