Hi, I developed an application that has a text box and a search button, when I enter a number in the text box and click the search button to transfer the value specified in the next step, where it uses this value to get the value from the database.
I use the following code to pass a value.
search_button.setClickable(true);
search_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String outlet_no = outlet_id.getText().toString();
System.out.println(outlet_no);
if(!outlet_no.isEmpty()){
@SuppressWarnings("deprecation")
SharedPreferences myPrefs = getApplicationContext().getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefsEditor.putString("outlet_id", outlet_no);
prefsEditor.commit();
Intent myIntent = new Intent(HomeActivity.this, StoreActivity.class);
startActivity(myIntent);
HomeActivity.this.startActivity(myIntent);
}
else{
Toast.makeText(getApplicationContext(), "Please enter an outlet id", Toast.LENGTH_SHORT);
}
}
});
My problem is that it does not pass value. Can someone help me with this, and also can any1 explain the code above to me since I haven't written it, and it's hard for me to understand it.
StoreActivity Side
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.store);
myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
mOutletID = myPrefs.getString("outlet_id", "0");
mOutletDetails = myPrefs.getString("outlet_details","{}");
Log.v("outlet_details",myPrefs.getString("outlet_details","{}"));
if(mOutletDetails != "{}"){
setOutletData(mOutletDetails);
}
else{
executeAjaxRequest();
}
}
user1881440
source
share