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

Apps Using Java with Android, help :(

Booocubs

Newbie
Now I know android works closely with java programming, so android is based off of java.
In my application, I want a spinner, with 8 choices, and when the "spin" button is pushed, I want the spinner to randomly choose one option.
My question is;
Can I create the spinner entirely with java code outside of android and then just insert the code into the .java file in eclipse? I'm familiar with java and would be able to pull this off if you can do it this way.

:(:(:(:(:(
 
That wont work since you got to make the code so it works with the android OS.. What you want to do is possible, But making android applications isn't as making normal desktop ones.. Try to check this website out if might give you a good start: What is Android? | Android Developers

I also recomend maybe doing some smaller applications before you start your bigger projects.
 
I'm not sure if it is possible, but really there isn't any need to. The following code will do exactly what you ask:

Code:
//aspinner is a global Spinner. Doesn't have to be, just so you can access it in the onTouch call

aspinner = (Spinner) findViewById(R.id.spin);
String[] params = new String[]{"SelectA","SelectB","SelectC"};
        ArrayAdapter<String> adapter2 =
            new ArrayAdapter<String> (this,
            android.R.layout.simple_spinner_dropdown_item,params);
        aspinner.setAdapter(adapter2);
        
        //IMPORTANT: This is onTouch and NOT onItemSelected
        aspinner.setOnTouchListener((new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                //Randomly select between 0-2
                Random r = new Random();
                aspinner.setSelection(r.nextInt()%3);
                return true; //returning true will prevent the options popping up
            }
        }));
 
I installed Java SE for my Windows 64 bit machine, but I can't find the program. Does it only run with linked up with the Compiler and/or Android? I can go to the DOS command and type in "java" and get whole lot of "Options" is that what's supposed to happen or is the supposed to be a "regular program" that opens up? Sorry for the Newbie question, I'm just starting out, as of yesterday ...

Thanks for any help/guidance anyone can lend !!!


Tim
 
I installed Java SE for my Windows 64 bit machine, but I can't find the program. Does it only run with linked up with the Compiler and/or Android? I can go to the DOS command and type in "java" and get whole lot of "Options" is that what's supposed to happen or is the supposed to be a "regular program" that opens up? Sorry for the Newbie question, I'm just starting out, as of yesterday ...

Thanks for any help/guidance anyone can lend !!!


Tim

Hi Tim,

What you've installed is the Java Runtime Environment for Windows. This is a program which is designed to run other compiled Java programs on Windows. Getting a list of options is the correct behaviour when you run "java" from the command prompt.

If you want to develop Android apps, you will need the Android Software Development Kit (SDK). Also you will need an Integrated Development Environment (IDE) to code Java in. Eclipse is the most common (if not recommended) IDE for Android development. After you install Eclipse, you'll need the Android Development Tools (ADT) plugin to integrate Eclipse with the Android SDK.

Finally you'll need to add the SDK components for versions of Android you want to code for the and setup an Android Virtual Device (AVD) to test on.

This isn't something you want to do solo if you're new to programming. I strongly recommend getting some books. Start with books on Java programming. Then progress to books specially on Android programming.
 
Back
Top Bottom