Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update:</strong></p> <p>My original solution below will work for this use case, but a much better solution is that of the <code>ViewHolder</code> pattern, as touched on by HailNaRoz. Although it isn't explained by HailNaRoz why his solution works, that solution uses a <code>ViewHolder</code> to aid <code>View</code> reuse and is the preferred method adopted by Google and the Android Dev community. The <code>ViewHolder</code> keeps a reference to the <code>Views</code> (<code>EditText</code>, <code>TextView</code>, <code>ImageView</code> etc), and allows you to add them back into the correct list row when it becomes visible.</p> <p>Its also worth looking at <code>RecyclerView</code>, which has since been introduced to aleviate some of these issues, which forces this methodology. <code>RecyclerView</code> is available as a support library that can be added in gradle</p> <p>See <a href="http://developer.android.com/training/improving-layouts/smooth-scrolling.html#ViewHolder" rel="nofollow">View Holder in List View</a> and <a href="http://developer.android.com/training/material/lists-cards.html" rel="nofollow">Creating Lists and Cards (Recycler View)</a></p> <p><strong>Original:</strong></p> <p>Your problem is that your <code>EditText</code> is being recycled. You are keeping hold of a copy of your <code>TextView</code> text and resetting it every time it is loaded, but not for your <code>EditText</code>.</p> <p>So you need a way to store the text in the <code>EditText</code> field and reset it in your <code>getView()</code> method.</p> <p>To do this you want to set up a <code>TextWatcher</code> after your if/else statement in <code>getView()</code>:</p> <pre><code>holder.editText.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) { } public void afterTextChanged(Editable s) { editTextList.put(position,s.toString()); } }); </code></pre> <p>This stores the value in a <code>HashMap</code> maintained separately. <code>position</code> is taken from the int parameter in your <code>getView()</code> method. You will need to make it final.</p> <p>The <code>HashMap</code>:</p> <pre><code>private HashMap&lt;Integer,String&gt; editTextList =new HashMap&lt;Integer,String&gt;(); </code></pre> <p>Then when you set your <code>TextView</code> text you also want to set the <code>EditText</code> value:</p> <pre><code>holder.text.setText(s); holder.editText.setText(editTextList.get(position)); </code></pre> <p>This should keep the current positions <code>editText</code> value in the correct <code>EditText</code> box.</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. This table or related slice is empty.
    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