I have list item with EditText in it, I don\'t know how many items there will be. I have a problem when I enter some text in EditText, and then scr
try this:
public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public String[] Current;
ArrayList MeterName, PreviousReading, Current_Reading;
JSONArray getArray_Meter_Reading;
public static HashMap myList=new HashMap();
public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) {
mInflater = LayoutInflater.from(context);
this.getArray_Meter_Reading = getArray_Meter_Reading;
MeterName = new ArrayList();
PreviousReading = new ArrayList();
for (int i = 0; i < getArray_Meter_Reading.length(); i++) {
try {
String Meter_Name = getArray_Meter_Reading.getJSONObject(i)
.getString("MeterName").toString();
String previous_Meter_Reading = getArray_Meter_Reading
.getJSONObject(i).getString("PrevMeterReading")
.toString();
MeterName.add(Meter_Name);
PreviousReading.add(previous_Meter_Reading);
// Meter[i]=MeterName.get(i);
// Previous[i]=PreviousReading.get(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// initialize myList
for(int i=0;i
Here I have included a HashMap object which will keep an eye on if EditText contains value or not.And when you scroll the listview,it will be rendered again by calling its getView method along with the text associated with each edittext.
In this code,when you firstly load listview,all your edittext will be with no text.once you enter some text,it will be noted in myList.So when you again render the list,your text would be prevented.
One more thing,you should implement textwatcher outside if(convertView==null)..else.. block.That's a better practice!