我在Bundle中放了一个String值(来自我的Search-Activity中的用户的Edittext输入)。然后我有了Bundle(Result-Activity)来检查用户是否没有使用Edittext。但它不起作用。如果陈述有问题。好像什么也没检查过。我调试并首先看到“If”被执行然后“Else”。有人能帮助我吗?
搜索的活性:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mDbHelper = new SBooksDbAdapter(this);
mDbHelper.open();
setContentView(R.layout.sbooks_search);
mTextSearch = (EditText)findViewById(R.id.text_search);
searchButton = (Button)findViewById(R.id.btn_search);
mTextSearch.setFocusableInTouchMode(true);
mTextSearch.setHint(R.string.button_hint);
searchButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
startSearch();
}
});
}
// Start Activity Search Result
public void startSearch(){
Bundle bundle = new Bundle();
bundle.putString(SBooksDbAdapter.KEY_TITLE_RAW, mTextSearch.getText().toString());
Intent intentSearch = new Intent(this, SBooksSearchResult.class);
intentSearch.putExtras(bundle);
this.startActivity(intentSearch);
}
结果-Acitity:
Bundle bundle = getIntent().getExtras();
String searchText = bundle.getString(SBooksDbAdapter.KEY_TITLE_RAW);
if(searchText != "")
{
// Do nothing
}
else {
searchText = "Hello" ;
}
答案 0 :(得分:1)
而不是:
if (searchText != "")
尝试:
if (!searchText.equals(""))