Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

someone PLEASE help

right I'm very new to coding and need help... ive got a number picker and i want it to go up or down by one when a button is press I want to make it as simple as possible im using eclipse ive been looking on the internet all day and ive got no where

thanks for the help in advance

8 Answers

samiff
samiff
31,206 Points

Post your code that you have so far, and that will make helping you a lot easier.

I havent got anything i dunno what to do to do it

samiff
samiff
31,206 Points

Sounds like you should take a look at Introduction to Programming. Although that uses JavaScript (unrelated to Java), it's a good way to start understanding programming.

I'm not sure exactly what you're trying to create, but the way something like that would work is that you'd have a variable, let's say clickCount, that would store a value.

You could then have a button which would contain an event handler (the event would be someone clicking it). Each time the button is clicked, the event handler is called, and code can be ran that would add/subtract from your clickCount variable.

Any reason you started with Java/Android/Eclipse in particular?

Im just trying to make a app to counts something if i click the plus button on a number picker or button and eclipse was the software treehouse said to use

James Barnett
James Barnett
39,199 Points

@James Allgood - There's a whole course here on Treehouse for learning to program on Android

yeah ive done the course I must have to use something like a on click listener then from there onwards I become stuck ive looked on google and theres nothing i can find and get it to work

Nathan Kluth
Nathan Kluth
12,124 Points

Hi James. Here is what I come up with. It's pretty crude, so you'll have to tweak it from here :)

public class MainActivity extends Activity {

Integer i = 20;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    Button up = (Button) findViewById(R.id.button1);
    Button down = (Button) findViewById(R.id.button2);

    final TextView text = (TextView) findViewById(R.id.textView1);
    text.setText("20");



    up.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            i++;
            text.setText(i.toString());
        }
    });

    down.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            i--;
            text.setText(i.toString());
        }
    });


}