Simplistic instructions from Spinner Selection to a Linear I

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Simplistic instructions from Spinner Selection to a Linear I

Postby ashywood » Sat May 23, 2009 2:53 pm

I know there are multiple snippets of information about multiple Spinner activities, but I hope mines will be a bit more simplistic in nature.

What I am trying to do is give a user a selection of planets by means of a Spinner interface. When user chooses said planet, they will be directed to a linear layout embedded with the planet's image. [Spinner -> Spinner Array -> Spinner Selection -> Image]

Here's my java:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.test.screen;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.View;
  10.  
  11. import android.widget.ArrayAdapter;
  12.  
  13. import android.widget.Button;
  14.  
  15. import android.widget.Spinner;
  16.  
  17.  
  18.  
  19. public class screen2 extends Activity
  20.  
  21. {
  22.  
  23.        
  24.  
  25.    @Override
  26.  
  27.    public void onCreate(Bundle savedInstanceState)
  28.  
  29.    {
  30.  
  31.       super.onCreate(savedInstanceState);
  32.  
  33.       setContentView(R.layout.screen2);
  34.  
  35.          
  36.  
  37.      //Begin Spinner Function
  38.  
  39.       Spinner s = (Spinner) findViewById(R.id.spinner1);
  40.  
  41.       ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
  42.  
  43.         this, R.array.planets, android.R.layout.simple_spinner_item);
  44.  
  45.       adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  46.  
  47.         s.setAdapter(adapter);
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  //New Stuff: Put activity to do when something is selected.
  54.  
  55.       s.setOnItemSelectedListener(
  56.  
  57.         new OnItemSelectedListener(){                                                    
  58.  
  59.         public void onItemSelected(                                                                      
  60.  
  61.        AdapterView parent, View view, int position, long id) {      
  62.  
  63.                  
  64.  
  65.       //How to refer to selected item.
  66.  
  67.       String selectedItemString = parent.getSelectedItem();
  68.  
  69.        }    
  70.  
  71.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

**************************************************************************************************************************
And here's my Array.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <resources>
  2.  
  3.  
  4.  
  5.     <string-array name="states">
  6.  
  7.         <item>Jupiter</item>
  8.  
  9.         <item>Pluto</item>
  10.  
  11.         <item>Mars</item>
  12.  
  13.         <item>Neptune</item>
  14.  
  15.         <item>Earth</item>
  16.  
  17.     </string-array>
  18.  
  19.    
  20.  
  21. </resources>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

*****************************************************************************************************************************

I appreciate any help that can be offered. It goes without saying I am new, but I humbly ask upon the help of the java/Android gurus. :D

~A~
ashywood
Freshman
Freshman
 
Posts: 5
Joined: Tue Apr 28, 2009 2:34 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests