I have 2 spinners and 1 textview.When i selected two different elements from these spinners textview must be changed everytime.For 1 spinner everything is OK but it doesnt work on 2 spinners.
Here's what i tried:
public class Chords extends Activity implements AdapterView.OnItemSelectedListener {
String[] notes = {"A", "B", "C", "D", "E", "F", "G"};
String[] mode = {"m","m7","5","M","7M","dim","aug","sus2"};
Spinner sp;
Spinner spinner2;
TextView textView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chords_screen);
System.out.println(notes.length);
textView = (TextView) findViewById(R.id.textView);
sp= (Spinner) findViewById(R.id.spinner);
spinner2=(Spinner) findViewById(R.id.spinner2);
ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,notes);
ArrayAdapter<String> adapter_state2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,mode);
adapter_state.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter_state2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter_state);
sp.setOnItemSelectedListener(this);
spinner2.setAdapter(adapter_state2);
sp.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
switch(position)
{
case 0:
textView.setText("Am");
break;
}
}
#Override
public void onNothingSelected (AdapterView < ? > parent){
}
}
You have 2 spinners. You set onItemSelected listener. but your implementation is wrong i think. In switch case you have to identify which spinner value is changing. you can do like this ..
I edited all code for you
public class MainActivity extends ActionBarActivity implements OnItemSelectedListener {
String[] notes = {"A", "B", "C", "D", "E", "F", "G"};
String[] mode = {"m","m7","5","M","7M","dim","aug","sus2"};
Spinner sp;
Spinner spinner2;
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialization
textView = (TextView) findViewById(R.id.textView);
sp = (Spinner) findViewById(R.id.spinner);
spinner2=(Spinner) findViewById(R.id.spinner2);
//creating adapter
ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,notes);
ArrayAdapter<String> adapter_state2 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,mode);
//setting drop down list type
adapter_state.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter_state2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//setting adapter to spinner
sp.setAdapter(adapter_state);
spinner2.setAdapter(adapter_state2);
//setting listener to spinner
sp.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
// TODO Auto-generated method stub
switch(parent.getId())
{
case R.id.spinner:
textView.setText(""+notes[position]);
break;
case R.id.spinner2:
textView.setText(""+mode[position]);
break;
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
To do so edit like this
case R.id.spinner:
textView.setText(sp.getSelectedItem().toString()+spinner2.getSelectedItem().toString());
break;
case R.id.spinner2:
textView.setText(sp.getSelectedItem().toString()+spinner2.getSelectedItem().toString());
break;
Related
I am new to android,and in this code i have two spinners and based on the values selected,different layouts should open accordingly. Im stuck with what logic should i use to open different layouts, inside the OnItemSelected for the spinner.Say i have 5 items in spinner and i have 5 different layouts for each item.So how should i do??
Any help or ideas would be much appreciated. Thanks in advance.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
// Spinner element
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
Button button = (Button) findViewById(R.id.button);
// Spinner click listener
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add("Maruti");
categories.add("Ford");
categories.add("Nissan");
categories.add("TATA");
List<String> types = new ArrayList<String>();
types.add("1Lakh-5Lakh");
types.add("5Lakh-10Lakh");
types.add("10Lakh-20Lakh");
types.add("20Lakh-50Lakh");
types.add("Above 50Lakhs");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ArrayAdapter<String> spinner2Adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,types);
spinner2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner1.setAdapter(dataAdapter);
spinner2.setAdapter(spinner2Adapter);
spinner1.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(SecondActivity.this,ThirdActivity.class);
startActivity(i);
}
});
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Spinner spinner1 = (Spinner)parent;
Spinner spinner2 = (Spinner)parent;
if(spinner1.equals(position))
{
}
if(spinner2.getId() == R.id.spinner2)
{
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}}
Try below.
check the onClickListener of button which will decide which activity to open.
Spinner spinner1;
Spinner spinner2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
// Spinner element
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
Button button = (Button) findViewById(R.id.button);
// Spinner click listener
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add("Maruti");
categories.add("Ford");
categories.add("Nissan");
categories.add("TATA");
List<String> types = new ArrayList<String>();
types.add("1Lakh-5Lakh");
types.add("5Lakh-10Lakh");
types.add("10Lakh-20Lakh");
types.add("20Lakh-50Lakh");
types.add("Above 50Lakhs");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ArrayAdapter<String> spinner2Adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,types);
spinner2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner1.setAdapter(dataAdapter);
spinner2.setAdapter(spinner2Adapter);
spinner1.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i;
if(spinner1_selected_item.equals("Maruti"))
{
if(spinner2_selected_item.equals("1Lakh-5Lakh"))
i=new Intent(SecondActivity.this,ThirdActivity.class);
if(spinner2_selected_item.equals("5Lakh-10Lakh"))
i=new Intent(SecondActivity.this,FourthActivity.class);
if(spinner2_selected_item.equals("10Lakh-20Lakh"))
i=new Intent(SecondActivity.this,FifthActivity.class);
}
startActivity(i);
}
});
}
String spinner1_selected_item;
String spinner2_selected_item;
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(spinner1.getId() == R.id.spinner1)
{
spinner1_selected_item = parent.getItemAtPosition(position).toString();
}
if(spinner2.getId() == R.id.spinner2)
{
spinner2_selected_item = parent.getItemAtPosition(position).toString();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}}
public class StartCalvert extends Activity {
Spinner spnr,spnr2;
String[] numsys = {
"Binary",
"Decimal",
"Octal",
"Hexadecimal"
};
// this numsys how will i declare
String[] numsys2 = {
"Binary",
"Decimal",
"Octal",
"Hexadecimal"
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startcalvert);
spnr2 = (Spinner)findViewById(R.id.spinner2);
spnr = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, numsys);
//declare here , like what above alike .
spnr.setAdapter(adapter);
spnr.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener()
Each Spinner has it's adapter has bind its Datasource with view on it so , most likely you need to make one for each Spinner and any other Data Views
in onCreate
spinner1 = (Spinner) findViewById(R.id.spinner1 );
spinner2 = (Spinner) findViewById(R.id.spinner2 );
ArrayAdapter<String> adapterSpinner1 = new ArrayAdapter<String>(
SpinnerActivity.this, R.layout.simple_spinner_item,
numsys);
spinner1.setDropDownViewResource(R.layout.simple_spinner_item);
spinner1.setAdapter(adapterSpinner1);
ArrayAdapter<String> adapterSpinner2 = new ArrayAdapter<String>(
SpinnerActivity.this, R.layout.simple_spinner_item,
numsys2);
spinner2.setDropDownViewResource(R.layout.simple_spinner_item);
spinner2.setAdapter(adapterSpinner2);
ItemSelectedListener itemSelectedListener = new ItemSelectedListener();
spinner1.setOnItemSelectedListener(itemSelectedListener);
spinner2.setOnItemSelectedListener(itemSelectedListener);
Declare inner class
class ItemSelectedListener implements OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View v, int position,
long arg3) {
LoggerGeneral.info("OnItemselected pressed");
switch (parent.getId()) {
case R.id.spinner1:
break;
case R.id.spinner2:
break;
default:
break;
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}
In my application i have used spinner and edit text.i have created an XML file and set it as background to the spinner which looks like a drop down arrow.When i click the spinner the items selected from spinner should be set in edit text but it displays in edit text as well spinner as the below image. can any one help me with this??
public class newcard extends Activity {
Spinner spinner;
Button btn;
EditText ed,ed1,ed2;
List<String> list;
private String[] countries_list={"01/2014","02/2014","03/2014","04/2014"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addnewcard);
btn= (Button) findViewById(R.id.button1);
spinner = (Spinner) findViewById(R.id.spinner2);
ed = (EditText) findViewById(R.id.editText3);
spinner.setFocusable(true);
spinner.setFocusableInTouchMode(true);
list = new ArrayList<String>();
list.add(" ");
list.add("select");
list.add("01/2014");
list.add("02/2014");
list.add("03/2014");
list.add("04/2014");
ArrayAdapter<String> adp = new ArrayAdapter<String>
(this, android.R.layout.simple_dropdown_item_1line, list);
adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(adp);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
//#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
// TODO Auto-generated method stub
switch(arg2) {
case 0 :
ed.setText("Select");
break;
case 1 :
ed.setText("01/2014");
break;
case 2 :
ed.setText("02/2014");
break;
case 3 :
ed.setText("04/2014");
break;
default :
ed.setText("Nothing");
break;
}
}
//#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
For setting spinner value to ""
public void onItemSelected(AdapterView<?> parent, View arg1, int arg2, long arg3)
{
item = (String) parent.getItemAtPosition(arg2);
((TextView) parent.getChildAt(0)).setText("");
}
http://i.stack.imgur.com/HGsTw.jpg
This is the error I get and the app just crashes and shows nothing!.
PS:When I moved those last 4 lines of code from the OnCreate method to the beginning of the OnItemSelected method I get no errors and this layout (http://i.stack.imgur.com/1DiLI.jpg) shows but no dropdown lists (I expect a list of colors when I click the arrow button next to background).
Here is my code:
public class SetLayout extends Activity implements OnItemSelectedListener {
TextView o_markertv, x_markertv, bcktv, gridtv;
String[] colors ={"Red", "Green", "Blue", "Black", "White"};
Spinner spinner1, spinner2, spinner3, spinner4;
LinearLayout bck;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setlayout);
bck= (LinearLayout) findViewById(R.id.bck);
o_markertv= (TextView) findViewById(R.id.o_markertv);
x_markertv= (TextView) findViewById(R.id.x_markertv);
bcktv= (TextView) findViewById(R.id.bcktv);
gridtv= (TextView) findViewById(R.id.gridtv);
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner3 = (Spinner) findViewById(R.id.spinner3);
spinner4 = (Spinner) findViewById(R.id.spinner4);
//Button BtnSubmit = (Button) findViewById(R.id.btnSubmit);
ArrayAdapter<String> adapter=new ArrayAdapter<String> (SetLayout.this,android.R.layout.simple_spinner_item,colors);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter);
spinner1.setOnItemSelectedListener(this);
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int position= spinner1.getSelectedItemPosition();
switch(position){ //red, green blue black white
case 0:
bck.setBackgroundColor(color.red);
break;
case 1:
bck.setBackgroundColor(color.green);
break;
case 2:
bck.setBackgroundColor(color.blue);
break;
case 3:
bck.setBackgroundColor(color.black);
break;
case 4:
bck.setBackgroundColor(color.white);
break;
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Hey guys I have code shown bellow, which is supposed to get the item selected from the first spinner - Poets and then show another spinner depending on input poem 1,2 or 3. Once An item is selected from the second spinner it should then show a text view.
My problem is that sometimes it works, sometimes it chooses randomly which spinner to show it would seem and almost every single time when I select an item from spinner 2, the text view is almost never shown and when it is it's normally text view entitled tree.
can anyone help? I do not see any errors so I am confused
code:
public class Poets extends Activity implements OnItemSelectedListener{
//defining variables
Spinner PoetSpinner, PoemSpinner1, PoemSpinner2, PoemSpinner3;
String Poets[] = {"","Robert Burns", "James Beattie", "Duncan MacGregor Crerar"};
String Poems1[] ={"", "Tam O Shanter", "Auld Lang Syne"};
String Poems2[] ={"", "Judgement Of Paris", "The Minstrel"};
String Poems3[] ={"", "A Poem Commemorating Robbie Burns", "My Bonnie Rowan Tree"};
TextView Tam, Auld, Judge, TheMin, rob, tree ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set to fullscreen mode
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN );
//set content view
setContentView(R.layout.poet);
initialize(); //call this method
}
public void initialize(){
//initializing items that are in the class
PoetSpinner = (Spinner) findViewById(R.id.spPoet);
PoemSpinner1 = (Spinner) findViewById(R.id.spPoem1);
PoemSpinner2 = (Spinner) findViewById(R.id.spPoem2);
PoemSpinner3 = (Spinner) findViewById(R.id.spPoem3);
Tam = (TextView) findViewById(R.id.tvSelectPoem1);
Auld = (TextView) findViewById(R.id.tvSelectPoem2);
Judge = (TextView) findViewById(R.id.tvSelectPoem3);
TheMin = (TextView) findViewById(R.id.tvSelectPoem4);
rob = (TextView) findViewById(R.id.tvSelectPoem5);
tree = (TextView) findViewById(R.id.tvSelectPoem6);
//setting up array adapters
//
//for each spinner
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.poet_arrays, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.poem_arrays1, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.poem_arrays2, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapter4 = ArrayAdapter.createFromResource(this, R.array.poem_arrays3, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
PoetSpinner.setAdapter(adapter);
PoetSpinner.setOnItemSelectedListener(this);
PoemSpinner1.setAdapter(adapter2);
PoemSpinner1.setOnItemSelectedListener(this);
PoemSpinner2.setAdapter(adapter3);
PoemSpinner2.setOnItemSelectedListener(this);
PoemSpinner3.setAdapter(adapter4);
PoemSpinner3.setOnItemSelectedListener(this);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String val = Poets[pos];
String val2 = Poems1[pos];
String val3 = Poems2[pos];
String val4 = Poems3[pos];
if (val.equals("Robert Burns")) {
PoemSpinner2.setVisibility(Spinner.GONE);
PoemSpinner1.setVisibility(Spinner.VISIBLE);
PoemSpinner3.setVisibility(Spinner.GONE);
}
if (val.equals("James Beattie")) {
PoemSpinner2.setVisibility(Spinner.VISIBLE);
PoemSpinner1.setVisibility(Spinner.GONE);
PoemSpinner3.setVisibility(Spinner.GONE);
}
if (val.equals("Duncan MacGregor Crerar")) {
PoemSpinner2.setVisibility(Spinner.GONE);
PoemSpinner1.setVisibility(Spinner.GONE);
PoemSpinner3.setVisibility(Spinner.VISIBLE);
}
if (val2.equals("Tam O Shanter")) {
Tam.setVisibility(View.VISIBLE);
Auld.setVisibility(View.GONE);
Judge.setVisibility(View.GONE);
TheMin.setVisibility(View.GONE);
tree.setVisibility(View.GONE);
rob.setVisibility(View.GONE);
}
if (val2.equals("Auld Lang Syne")) {
Auld.setVisibility(View.VISIBLE);
Judge.setVisibility(View.GONE);
TheMin.setVisibility(View.GONE);
tree.setVisibility(View.GONE);
Tam.setVisibility(View.GONE);
rob.setVisibility(View.GONE);
}
if (val3.equals("Judgment Of Paris")) {
Judge.setVisibility(View.VISIBLE);
TheMin.setVisibility(View.GONE);
tree.setVisibility(View.GONE);
Tam.setVisibility(View.GONE);
Auld.setVisibility(View.GONE);
rob.setVisibility(View.GONE);
}
if (val3.equals("The Minstrel")) {
TheMin.setVisibility(View.VISIBLE);
tree.setVisibility(View.GONE);
Tam.setVisibility(View.GONE);
Auld.setVisibility(View.GONE);
Judge.setVisibility(View.GONE);
rob.setVisibility(View.GONE);
}
if (val4.equals("A Poem Commemorating Robbie Burns")) {
rob.setVisibility(View.VISIBLE);
tree.setVisibility(View.GONE);
Tam.setVisibility(View.GONE);
Auld.setVisibility(View.GONE);
Judge.setVisibility(View.GONE);
TheMin.setVisibility(View.GONE);
}
if (val4.equals("My Bonnie Rowan Tree"))
tree.setVisibility(View.VISIBLE);
Tam.setVisibility(View.GONE);
Auld.setVisibility(View.GONE);
Judge.setVisibility(View.GONE);
TheMin.setVisibility(View.GONE);
rob.setVisibility(View.GONE);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
I have a feeling you have overcomplicated things a little. You can make what you want with 2 spinners and only one textview.
The first spinner will contain the poets, and based on the poet selected in this spinner you can modify the content of the second spinner in which you can have the poems of the selected poet. You can then show the selected poems name in the textview when the poem is selected in the second spinner. I would try with something like this:
public class Poets extends Activity implements
OnItemSelectedListener {
// defining variables
Spinner PoetSpinner, PoemSpinner;
String Poets[] = { "", "Robert Burns", "James Beattie",
"Duncan MacGregor Crerar" };
String Poems1[] = { "", "Tam O Shanter", "Auld Lang Syne" };
String Poems2[] = { "", "Judgement Of Paris", "The Minstrel" };
String Poems3[] = { "", "A Poem Commemorating Robbie Burns",
"My Bonnie Rowan Tree" };
TextView selectedPoem;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set to fullscreen mode
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// set content view
setContentView(R.layout.poet);
initialize(); // call this method
}
public void initialize() {
// initializing items that are in the class
PoetSpinner = (Spinner) findViewById(R.id.spPoet);
PoemSpinner = (Spinner) findViewById(R.id.spPoem);
// Hide the second spinner
PoemSpinner.setVisibility(View.GONE);
selectedPoem = (TextView) findViewById(R.id.tvSelectPoem1);
// setting up array adapters
//
// for each spinner
ArrayAdapter<CharSequence> adapter = ArrayAdapter
.createFromResource(this, R.array.poet_arrays,
android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
PoetSpinner.setAdapter(adapter);
PoetSpinner.setOnItemSelectedListener(this);
PoemSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Object poem = parent.getItemAtPosition(position);
selectedPoem.setText(poem.toString());
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
ArrayAdapter<CharSequence> adapter = null;
switch (pos) {
case 1:
adapter = ArrayAdapter.createFromResource(this,
R.array.poem_arrays1, android.R.layout.simple_spinner_item);
break;
case 2:
adapter = ArrayAdapter.createFromResource(this,
R.array.poem_arrays2, android.R.layout.simple_spinner_item);
break;
case 3:
adapter = ArrayAdapter.createFromResource(this,
R.array.poem_arrays3, android.R.layout.simple_spinner_item);
break;
default:
// Hide the poem spinner
PoemSpinner.setVisibility(View.GONE);
break;
}
if (adapter != null) {
// Set the poem spinners content and show the spinner
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
PoemSpinner.setAdapter(adapter);
PoemSpinner.setVisibility(View.VISIBLE);
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
Of course you will have to delete the unused views from your xml.
I hope i was clear enough, and the code works as you wanted to.