On Button Click Deletes Existing Data From Textview After Re-launching
Whenever i relaunch my app, getting old values into TextView if some stored by me, but facing a small issue, now after relaunching my app once i do tap on button, it deletes earlie
Solution 1:
Try this..
btnInput.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View arg0) {
// TODO Auto-generated method stubString check = editTextInput.getText().toString();
if(check.equalsIgnoreCase("ABC"))
{
strInput = textViewResult.getText().toString()+","+check;
Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_LONG).show();
textViewResult.setText(strInput);
editTextInput.setText("");
}
else {
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_LONG).show();
}
}
});
EDIT
Use split("")
String[] total_abc = textViewResult.getText().toString().split(",");
int total = total_abc.length;
Solution 2:
put prefs.edit().putString("autoSave", s.toString()).commit(); on the OnClick event
and remove textViewResult.setText(prefs.getString("autoSave", "")); instead of it write textViewResult.setText(prefs.getString("autoSave")); you just specify the key value when getting from sharedpreferences thats why you get blank
Post a Comment for "On Button Click Deletes Existing Data From Textview After Re-launching"