How to get EditText value from Sub-Activity? With a condition that in Sub-Activity I click back icon on the phone there's no error? This is my Sub-Activity code
public class SBooksSearch extends Activity {
private EditText mTextSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sbooks_search);
mTextSearch = (EditText)findViewById(R.id.edit_search);
Button searchButton = (Button)findViewById(R.id.btn_search);
searchButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent data = new Intent();
data.putExtra(SBooksDbAdapter.KEY_TITLE_RAW, mTextSearch.getText().toString());
setResult(RESULT_OK, data);
finish();
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
}
@Override
protected void onPause(){
super.onPause();
}
@Override
protected void onResume(){
super.onResume();
}
}
This is my Activity-Result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
switch(requestCode){
case ACTIVITY_SEARCH:
Bundle extras = getIntent().getExtras();
mTitleRaw = extras != null ? extras.getString(SBooksDbAdapter.KEY_TITLE_RAW) : null;
if(mTitleRaw!=null){
Cursor cursor = mDbHelper.searchData(mTitleRaw);
String[] from = new String[]{ SBooksDbAdapter.KEY_ROWID,
SBooksDbAdapter.KEY_TITLE, SBooksDbAdapter.KEY_LYRICS };
int[] to = new int[]{ R.id.id, R.id.title, R.id.lyrics };
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, R.layout.sbooks_row, cursor, from, to );
setListAdapter(adapter);
}
break;
}
}