Using a spinner on a different view

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

Using a spinner on a different view

Postby tsdev » Tue Dec 01, 2009 3:35 am

Having a problem loading an array into a spinner that is located on a different view. The array is defined properly in arrays.xml with a name of beerstyles. The beerstylespinner is defined as the id of a spinner in carbonationcalculator_view.xml. This works when the code is in the main java class but not the additional carbonationcalculator class. Everything works with the exception of the spinner not being populated with the array.

Here is the code:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.carbonationcalculator_view);

Spinner s = (Spinner) findViewById(R.id.beerstylespinner);

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.beerstyles, R.layout.carbonationcalculator_view);

adapter.setDropDownViewResource(R.layout.carbonationcalculator_view);

s.setAdapter(adapter);
tsdev
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Dec 01, 2009 3:31 am

Top

Postby qlimax » Wed Dec 02, 2009 11:50 pm

try this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
  2.  
  3. this, R.array.beerstyles, android.R.layout.simple_spinner_item);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


instead of

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
  2.  
  3. this, R.array.beerstyles, R.layout.carbonationcalculator_view);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4



and

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



bye :wink:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Re: Using a spinner on a different view

Postby chris123 » Thu Dec 10, 2009 3:36 am

try this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ArrayAdapter<CharSequence> adapter = new ArrayAdapter(
  3.  
  4.                 this,  R.layout.carbonationcalculator_view, getResources().getStringArray( R.array.beerstyles));
  5.  
  6.  
  7.  
  8.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


instead of:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
  3.  
  4.                 this,  R.array.beerstyles, R.layout.carbonationcalculator_view);
  5.  
  6.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
chris123
Freshman
Freshman
 
Posts: 3
Joined: Fri Nov 27, 2009 9:57 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests