0

I'm retrieving string data from my sqlitedatabase and compare in to my local variable. But its not working. It goes like this codes below.

String hole1 = " ";
Cursor cc = save.rawQuery("Select *from " +data + " where Mobile = '"+ number +"'", null);
cc.moveToFirst();
hole1 = cc.getString(cc.getColumnIndex("Hole1"));
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(  
                    this,  
                    R.layout.spinnerlayout,  
                    new String[] { hole1,"1", "2", "3", "4","5","6","7","8","9" });  adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
((Spinner) findViewById(R.id.soloscorehole1front9)).setAdapter(adapter1);

if( ((Spinner) findViewById(R.id.soloscorehole1front9)).getSelectedItem().toString() == hole1){
                Toast.makeText(Activity.this,"True!", Toast.LENGTH_LONG).show();
            }

Can anyone point what is wrong with this simple codes?

2 Answers 2

2

You shouldn't use == to compare strings. Use string1.equals(string2) instead. Using == compares if the reference to each string is equal whereas .equals() compares the values of the strings

Sign up to request clarification or add additional context in comments.

Comments

2

String comp like this would be better

().getSelectedItem().toString().equals(hole);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.