0

我正在从我的 sqlitedatabase 中检索字符串数据并与我的本地变量进行比较。但它不起作用。它就像下面的代码。

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

谁能指出这个简单的代码有什么问题?

4

2 回答 2

2

像这样的字符串组合会更好

().getSelectedItem().toString().equals(hole);
于 2013-01-10T04:26:30.180 回答
2

你不应该==用来比较字符串。改为使用string1.equals(string2)==如果对每个字符串的引用相等,则使用比较,而.equals()比较字符串的值

于 2013-01-10T04:27:13.563 回答