Returning a variable in a public void...

Posted by James Rattray on Stack Overflow See other posts from Stack Overflow or by James Rattray
Published on 2010-04-20T22:01:49Z Indexed on 2010/04/20 23:13 UTC
Read the original article Hit count: 283

Hello, I'm abit new to programming Android App's, however I have come across a problem, I can't find a way to make global variables -unlike other coding like php or VB.NET, are global variables possible? If not can someone find a way (and if possible implement the way into the code I will provide below) to get a value from the variable 'songtoplay' so I can use in another Public Void...

Here is the code:

    final Spinner hubSpinner = (Spinner) findViewById(R.id.myspinner);
    ArrayAdapter adapter = ArrayAdapter.createFromResource( this, R.array.colours, android.R.layout.simple_spinner_item); adapter
    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    hubSpinner.setAdapter(adapter);
    //
    hubSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
             //code
          Object ttestt = hubSpinner.getSelectedItem();
          final String test2 = ttestt.toString();
          Toast message1 = Toast.makeText(Textbox.this, test2, Toast.LENGTH_LONG);
        message1.show();    
        String songtoplay = test2;
          // Need songtoplay to be available in another 'Public Void'
        }
        public void onNothingSelected(AdapterView<?> parentView) {
             //Code
        }
    });

Basically, it gets the value from the Spinner 'hubSpinner' and displays it in a Toast. I then want it to return a value for string variable 'songtoplay' -or find a way to make it global or useable in another Public Void, (Which is will a button, -loading the song to be played)

Please help me,

Thanks alot.

James

© Stack Overflow or respective owner

Related posts about android

Related posts about java