Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>try this:</p> <pre><code>public class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public String[] Current; ArrayList&lt;String&gt; MeterName, PreviousReading, Current_Reading; JSONArray getArray_Meter_Reading; public static HashMap&lt;Integer,String&gt; myList=new HashMap&lt;Integer,String&gt;(); public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) { mInflater = LayoutInflater.from(context); this.getArray_Meter_Reading = getArray_Meter_Reading; MeterName = new ArrayList&lt;String&gt;(); PreviousReading = new ArrayList&lt;String&gt;(); for (int i = 0; i &lt; 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&lt;JSON_ARRAY_LENGTH;i++) { myList.put(i,""); } } public int getCount() { return getArray_Meter_Reading.length(); } public Object getItem(int position) { // TODO Auto-generated method stub return position; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder holder; final int pos=position; if (convertView == null) { convertView = mInflater.inflate(R.layout.meter_reading_list, null); holder = new ViewHolder(); holder.adp_MeterName = (TextView) convertView .findViewById(R.id.txt_Meter_Name); holder.adp_Previous = (TextView) convertView .findViewById(R.id.txt_Previous); holder.adp_Current = (EditText) convertView .findViewById(R.id.ed_Current); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.adp_Current.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } public void afterTextChanged(Editable s) { Current[holder.ref] = s.toString(); myList.put(pos,s.toString.trim()); } }); holder.ref = position; holder.adp_MeterName.setText(MeterName.get(position)); holder.adp_Previous.setText(PreviousReading.get(position)); // holder.adp_Current.setHint(MeterName.get(position)); // holder.adp_Current.setText(PreviousReading.get(position)); holder.adp_Current.setText(myList.get(position)); return convertView; } class ViewHolder { TextView adp_MeterName, adp_Previous; EditText adp_Current; int ref; } } </code></pre> <p>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.</p> <p>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.</p> <p>One more thing,you should implement textwatcher outside if(convertView==null)..else.. block.That's a better practice!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload