0

I have a list view and each row containing a TextView and EditText . while click in the EditText box soft key board gets open and i'm entering the value. After that while pressing back button to close the key board my list view gets refreshed and all the values entered in EditText also gone.

Please help me how to keep the values while key board gets closed?

if (ConvertViewP == null) {
            LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
        }
Vignesh
  • 2,295
  • 7
  • 33
  • 41

2 Answers2

0

I suggest you that you use SharedPreferences:

SharedPreferences

write the values into your preferences by leaving the application and write them back when you start/enter your application.

works realy fine for me.

nano_nano
  • 12,351
  • 8
  • 55
  • 83
  • while closing the keyboard after entering value in the text box itself value gets removed, how i ll store in Shared Preference? – Vignesh Mar 13 '13 at 13:34
  • There is textWatchListener for EditText. Just try that to store data – Ramachandra Reddy Avula Mar 13 '13 at 13:37
  • I made a change in code, now im inflating layout only when the convert view is null, so the text is visible now but value is moved to some other row text box while closing the key board.... see my code in my question... – Vignesh Mar 13 '13 at 13:55
0

You can hold it all just in one variable. E.g. having some hashmap in your ListActivity

Map<Integer, String> mHashMap = new HashMap<Integer, String>();

Where the key will be the position of list item and value is the text inputed into the EditText thanks to the listener set on it. (Counting Chars in EditText Changed Listener). And in ListAdapter.getView(int position, View convertView, ViewGroup parent) you'll make use of mHashMap and will get the value by position to be set into EditText if any.

If you want to retain the values during the screen orientation changes, you can easily do it, cuz Map is Parcelable and can be added to the Bundle (Saving Android Activity state using Save Instance State, Android HashMap in Bundle?)

Community
  • 1
  • 1
riwnodennyk
  • 8,140
  • 4
  • 35
  • 37