views:

260

answers:

1

Hi, I put a String value (Edittext input from user in my Search-Activity) in Bundle. Then I get the Bundle (Result-Activity) to check if the user left the Edittext with no value. But It's not work, my If statement have something wrong, it seems like nothing was checked. I debug and saw the code run "If" and then "Else". Can someone help me? Search-Activity:

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

Result-Acitity:

Bundle bundle = getIntent().getExtras();     
 String searchText = bundle.getString(SBooksDbAdapter.KEY_TITLE_RAW);  

 if(searchText != "")
 {
  // Do nothing   
 }
 else { 
  searchText = "Hello" ;
 }
+1  A: 

Instead of:

if (searchText != "")

try:

if (!searchText.equals(""))
Shaun K.
Thanks! It's work!
Dennie