Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:16:52+00:00 2026-06-13T07:16:52+00:00

Why is this not working ?! if(itemx == Test number item 0) { Log.i(Dropdown,

  • 0

Why is this not working ?!

if(itemx == "Test number item 0")
    {
    Log.i("Dropdown", "inside if");
    us_lo_ans_hold.setText("0x");
    }; 

if itemx is a String and it has the string ‘Test number item 0’.

I am creating my first spinner.

Here is the spinner code within the onCreate block of the Activity:

    Spinner us_lo_spinner = (Spinner) findViewById(R.id.ul_ans_spinner); 
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.test_defaults , android.R.layout.simple_spinner_item); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    us_lo_spinner.setAdapter(adapter); 

 // Spinner click listener 
us_lo_spinner.setOnItemSelectedListener(this);

Here is the String array in the strings.xml:

<string name="spin_title_ulover_ans">Spinner default:</string> 
<string-array name="test_defaults"> 
    <item>Test number item 0</item>
    <item>Test number item 1</item> 
    <item>Test number item 2</item> 
    <item>Test number item 3</item> 
    <item>Test number item 4</item> 
</string-array>

Here is the onItemSelected:

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
{
    Log.i("XXX_Dropdown", "XXXX");
    TextView us_lo_ans_hold = (TextView)findViewById(R.id.us_lo_ans_holdtest);
    // On selecting a spinner item 
    String itemx = arg0.getSelectedItem().toString();
    us_lo_ans_hold.setText("oppp12");
    Log.i("Dropdown", "item: " + itemx);
    Log.i("Dropdown", "arg1: " + arg1);
    Log.i("Dropdown", "arg2: " + arg2);
    Log.i("Dropdown", "arg3: " + arg3);
    // Showing selected spinner item 
    if(itemx == "Test number item 0")
        {
        Log.i("Dropdown", "inside if");
        us_lo_ans_hold.setText("0x");
        }; 

}

From all the Log.i(,)s I put in I can tell the itemx is correct, it has the correct string when an item in the spinner is selected.
Yet the IF will not work.

If I change the IF to this:

if(arg2 == 0)
    {
    Log.i("Dropdown", "inside if");
    us_lo_ans_hold.setText("0x");
    }; 

it will work; BUT that is not what I want!

So… why is this not working ?!:

if(itemx == "Test number item 0")
    {
    Log.i("Dropdown", "inside if");
    us_lo_ans_hold.setText("0x");
    }; 

if itemx is a String and it has the string ‘Test number item 0’. ?


also how or when would ‘onNothingSelected’ be called?
When you hit the back button ?
When you select the item already selected?
My ‘onNothingSelected’ is never called !

public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub
    Log.i("Dropdown", "in NOTHING SELECTED");
    TextView us_lo_ans_hold = (TextView)findViewById(R.id.us_lo_ans_holdtest);
    us_lo_ans_hold.setText("nothing selected");
}

Tried putting in the onCreate block of the Activity like the:

    // Spinner click listener 
    us_lo_spinner.setOnItemSelectedListener(this);

us_lo_spinner.onNothingSelected(this)   

but the ~compiler~ does like that.

So… how or when is ‘onNothingSelected’ called and how is it hooked up to a spinner ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:16:53+00:00Added an answer on June 13, 2026 at 7:16 am

    If your itemx is a variable then you cant compare two strings with ==. Use instead items.equals("Test number item 0");

    == compares objects and equals() compare string values.
    Take a look a this post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So why is this not working? I'm creating a regex that will match a
Why is this not working $(this).parents(tr).find(td:eq(2)).html() I cant seam to get the text getthis
I want to know i can do something similar to this (not working) code
This is not working. Firebug is not throwing any error though. HTML: <table> <tr><td>BookA</td><td><a
This is not working and it is driving me nuts. I have in the
On whatever reason this is not working (says 'file not found'), set in=c:\myprogram\_save cd
Why is this thing not working? [Database(Name=Relationships_Test)] [Table(Name = Order)] public class Order {
I am not sure why this is not working. Perhaps I am missing something
I am wondering why this is not working please help me. Here is my
I don't understand why this is not working. It should be very easy. upload.php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.