比较串来串不工作当字符串来自SQLiteDatabase字符串、工作、串来串不、SQLiteDatabase

由网友(你的眼眸印在我心间)分享简介:我是从我的sqlitedatabase检索字符串数据和比较,以我的本地变量。但它不工作。它是这样C $ CS低于这个$。I'm retrieving string data from my sqlitedatabase and compare in to my local variable. But its not...

我是从我的sqlitedatabase检索字符串数据和比较,以我的本地变量。但它不工作。它是这样C $ CS低于这个$。

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();
            }

任何人都能指出什么是错的这个简单的codeS?

Can anyone point what is wrong with this simple codes?

推荐答案

您不应使用 == 比较字符串。使用 string1.equals(字符串2)代替。使用 == 进行比较,如果参照每个字符串相等,而 .equals()比较字符串的值

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

阅读全文

相关推荐

最新文章