Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was having the exact same problem with a project I was working on. All solutions I had found also mentioned using the <code>textChangeListener</code>, however due to the nature of the list, and with an <code>EditText</code> in each row view, this was very inefficient. I took a separate approach using the <code>EditText.setOnFocusChangeListener()</code>. </p> <p>I attached this to each EditText within the getView method. The reason this works so well is it is called when the user switches to a different edittext or scrolls so the current row is off the screen which causes the <code>EditText</code> to lose focus. </p> <p>In the onFocusChange(View v, boolean hasFocus) within the listener I simply put:</p> <pre><code>if (!hasFocus) { EditText et = (EditText) v.findViewById(R.id.groupAmount); data.get(position).put("dueAmount", et.getText().toString().trim()); } </code></pre> <p>In my example I am storing the entered value into my data used to populate the views on each getView call, but this should still show how to access the data the User entered. Just make sure you attempt to take this stored data and try populating the editText at the corresponding position.</p> <p>Hope this helps.</p> <p><strong>Posting my full adapter here for reference</strong></p> <pre><code>public class memberlistadapter extends BaseAdapter { private LayoutInflater mInflater; public ArrayList&lt;Hashtable&lt;String, String&gt;&gt; data; ViewHolder viewHolder; public static HashMap&lt;Integer,String&gt; myList=new HashMap&lt;Integer,String&gt;(); public memberlistadapter(Context context) { mInflater = LayoutInflater.from(context); } public memberlistadapter(Activity activity, ArrayList&lt;Hashtable&lt;String, String&gt;&gt; objects) { super(); mInflater = activity.getLayoutInflater(); //this.activity = activity; this.data = objects; Log.d("data", data.toString()); } public void clear() { this.data.clear(); viewHolder = null; } public void setData(ArrayList&lt;Hashtable&lt;String, String&gt;&gt; data) { this.data = data; } public int getCount() { return data.size(); } public Object getItem(int item) { return data.get(item); } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.member_amount_child, null); viewHolder = new ViewHolder(); viewHolder.nameText = (TextView) convertView.findViewById(R.id.grp_amt_child); viewHolder.amountText = (EditText) convertView.findViewById(R.id.groupAmount); viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.memberCheckNotif); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } //Log.d("data at "+position, data.get(position).toString()); String amt = data.get(position).get("dueAmount"); String name = data.get(position).get("name"); String check = data.get(position).get("reminder"); viewHolder.nameText.setText(name); try { if (amt.length() &gt; 0 &amp;&amp; !amt.equalsIgnoreCase("0")) { viewHolder.amountText.setText(amt); } else { viewHolder.amountText.setText(""); } } catch (Exception e) { viewHolder.amountText.setText(""); } viewHolder.amountText.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { EditText et = (EditText) v.findViewById(R.id.groupAmount); data.get(position).put("dueAmount", et.getText().toString().trim()); } } }); try { if (check.equalsIgnoreCase("true")) { viewHolder.checkBox.setChecked(true); } else { viewHolder.checkBox.setChecked(false); } } catch (Exception e) { viewHolder.checkBox.setChecked(false); } viewHolder.checkBox.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (((CheckBox) v).isChecked()) { data.get(position).put("reminder", "True"); } else { data.get(position).put("reminder", "False"); } } }); if (position == 0) { viewHolder.checkBox.setVisibility(View.GONE); viewHolder.amountText.setVisibility(View.GONE); viewHolder.nameText.setVisibility(View.GONE); } else { viewHolder.checkBox.setVisibility(View.VISIBLE); viewHolder.amountText.setVisibility(View.VISIBLE); viewHolder.nameText.setVisibility(View.VISIBLE); } return convertView; } static class ViewHolder { TextView nameText; EditText amountText; CheckBox checkBox; } } </code></pre>
    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. 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