Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting text with spinner is not working for only one item from my list, how to resolve?
    primarykey
    data
    text
    <p>I have a problem with the code below, I have a spinner that has the names of three poets and when one is picked, it sets the content of the second spinner and when a poem is selected from the second spinner that sets the text view contents to the poem. This works for every single one except the Judgment of Paris poem which when chose does nothing, can anyone see why?</p> <p>this is the name of the string copy and pasted </p> <pre><code>string name="judgement" </code></pre> <p>code:</p> <pre><code> // 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.tvSelectedPoem); // setting up array adapters // // for each spinner ArrayAdapter&lt;CharSequence&gt; 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&lt;?&gt; parent, View view, int position, long id) { Object poem = parent.getItemAtPosition(position); if("Tam O Shanter".equals(poem.toString())){ selectedPoem.setText(getString(R.string.tamO)); } if("Auld Lang Syne".equals(poem.toString())){ selectedPoem.setText(getString(R.string.auld)); } if("Judgement Of Paris".equals(poem.toString())){ selectedPoem.setText(getString(R.string.judgement)); } if("The Minstrel".equals(poem.toString())){ selectedPoem.setText(getString(R.string.minstrel)); } if("A Poem Commemorating Robbie Burns".equals(poem.toString())){ selectedPoem.setText(getString(R.string.rob)); } if("My Bonnie Rowan Tree".equals(poem.toString())){ selectedPoem.setText(getString(R.string.row)); } } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } }); } public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) { ArrayAdapter&lt;CharSequence&gt; 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); } </code></pre> <p>the XML file</p> <pre><code> &lt;string name="tamO"&gt; But pleasures are like poppies spread, You seize the flower, its bloom is shed; Or like the snow falls in the river, A moment white--then melts for ever; Or like the borealis race, That flit ere you can point their place; Or like the rainbow\'s lovely form Evanishing amid the storm.-- Nae man can tether time or tide; The hour approaches Tam maun ride; That hour, o\' night\'s black arch the key-stane, That dreary hour he mounts his beast in; And sic a night he taks the road in As ne\'er poor sinner was abroad in. &lt;/string&gt; &lt;string name="auld"&gt; For auld lang syne, my dear, For auld lang syne. We\'ll tak a cup o\' kindness yet, For auld lang syne. And surely ye\'ll be your pint stowp! And surely I\'ll be mine! And we\'ll tak a cup o\'kindness yet, For auld lang syne. We twa hae run about the braes, And pou\'d the gowans fine; But we\'ve wander\'d mony a weary fit, Sin\' auld lang syne. &lt;/string&gt; &lt;string name="judgement"&gt; Up the broad cliffs, that tower\'d immense to heaven, Green wav\'d the lofty pines, on every side; Save where, fair-opening to the beam of even, A dale sloped gradual to the valley wide. Echoed the vale with many a chearful note; The various lowe of herds resounding long, The shrilling pipe, the mellow horn remote, And social clamours of the festive throng. For now, low-hovering o\'er the western main, Where amber clouds begirt his dazzling throne, The sun with ruddier verdure deck\'d the plain; And lakes, and streams, and spires triumphal shone; &lt;/string&gt; &lt;string name="minstrel"&gt; Of chance or change O let not man complain, Else shall he never never cease to wail: For, from th\' imperial dome, to where the swain Rears the lone cottage in the silent dale, All feel th\' assault of fortune\'s fickle gale; Art, empire, earth itself, to change are doom\'d; Earthquakes have raised to heaven the humble vale, And gulphs the mountain\'s mighty mass entomb\'d, And where th\' Atlantick rolls wide continents have bloom\'d. But sure to foreign climes we need not range, Nor search the antient records of our race, To learn the dire effects of time and change, Which in ourselves, alas, we daily trace. Yet at the darken\'d eye, the wither\'d face, Or hoary hair, I never will repine: But spare, O Time, whate\'er of mental grace, Of candour, love, or sympathy divine, Whate\'er of fancy\'s ray, or friendship\'s flame is mine. &lt;/string&gt; &lt;string name="rob"&gt; He touched our country\’s ancient harp With truest patriotic fire; Forth thrilling came soul-stirring strains, Man\’s nobler actions to inspire. The cottar\’s fireside, \‘neath his spell, Becomes at once a hallowed shrine; His hymn to Mary swells the heart, And fills the eye his Auld Lang Syne. Not to his native land alone His genius and his fame belong, In other climes is treasured dear His matchless legacy of song. His melodies have echoing gone To continents and isles afar; They cheer and gladden hearts alike \‘Neath Southern Cross and Polar Star. &lt;/string&gt; &lt;string name="row"&gt; Thrice welcome sweet green spray Culled from my Rowan Tree, By loved ones far away, In Bonnie Amulree. In Boyhood\’s days thy root Was planted by my hand; Just ere I left my dear, My Scottish fatherland. Thou but a sapling then, Though now a sheltering tree, While warblers in thy boughs, Sing sweetest melodies. &lt;/string&gt; &lt;string-array name="film_arrays"&gt; &lt;item&gt;Please Select...&lt;/item&gt; &lt;item&gt;Sean Connery&lt;/item&gt; &lt;item&gt;Billy Connolly&lt;/item&gt; &lt;item&gt;James McAvoy&lt;/item&gt; &lt;item&gt;Karen Gillan&lt;/item&gt; &lt;item&gt;Kelly Macdonald&lt;/item&gt; &lt;item&gt;Ashley Jensen&lt;/item&gt; &lt;/string-array&gt; &lt;string-array name="poet_arrays"&gt; &lt;item&gt;Please Select...&lt;/item&gt; &lt;item&gt;Robert Burns&lt;/item&gt; &lt;item&gt;James Beattie&lt;/item&gt; &lt;item&gt;Duncan MacGregor Crerar&lt;/item&gt; &lt;/string-array&gt; &lt;string-array name="poem_arrays1"&gt; &lt;item&gt;Please Select...&lt;/item&gt; &lt;item&gt;Tam O Shanter&lt;/item&gt; &lt;item&gt;Auld Lang Syne&lt;/item&gt; &lt;/string-array&gt; &lt;string-array name="poem_arrays2"&gt; &lt;item&gt;Please Select...&lt;/item&gt; &lt;item&gt;Judgment Of Paris&lt;/item&gt; &lt;item&gt;The Minstrel&lt;/item&gt; &lt;/string-array&gt; &lt;string-array name="poem_arrays3"&gt; &lt;item&gt;Please Select a...&lt;/item&gt; &lt;item&gt;A Poem Commemorating Robbie Burns&lt;/item&gt; &lt;item&gt;My Bonnie Rowan Tree&lt;/item&gt; &lt;/string-array&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload