4

Good day!

I'm carrying a ListView inside a EditText, where the user to scroll the value entered in the EditText changes position.

How should I handle this?

I thank!

Method getView():

public View getView(final int position, View convertView, ViewGroup parent){

final Sapatos sapato = lista.get(position);  

if (convertView == null){  

    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
    holder = new ViewHolder();  

    convertView = inflater.inflate(R.layout.list_pedidos, null);  

    holder.img = (ImageView) convertView.findViewById(R.id.imgPed);  
    holder.edt = (EditText)convertView.findViewById(R.id.editText1);  

    final LinearLayout layout;  
    layout = (LinearLayout)convertView.findViewById(R.id.LayoutPed);  


    convertView.setTag(holder);  

} else{  
    holder = (ViewHolder) convertView.getTag();  
}  


holder.img.setImageResource(sapato.getImagem());  
holder.edt.setText(""); //adicionei somente esta linha  

return convertView;  

}

  • 2
    Do you mean that you have edit text inside every list item ? – Lukap Jan 20 '12 at 12:24
  • I don't really understand the question...can you post some code? – iaindownie Jan 20 '12 at 12:44
  • Yes! When I type a value in an EditText and navigate the ListView, this value is being assigned to other lines as I traverse the list. – Matheus Mendes Jan 20 '12 at 12:47
  • I posted the method getView(). – Matheus Mendes Jan 20 '12 at 13:01
  • It seems like your EditText is being recycled (via `convertView`) and redisplayed in new list items. You may need to keep an array of Strings in your `ListAdapter` to keep track of the state of each EditText. This line: `holder.edt.setText("");` makes it seem like the EditTexts should always come up empty when scrolled onto the screen, though. – Jonba Jan 23 '12 at 00:43
  • You should probably look at [this answer](http://stackoverflow.com/questions/7738527/getting-an-issue-while-checking-the-dynamically-generated-checkbox-through-list/7739006#7739006). – Lalit Poptani Jan 23 '12 at 07:00

1 Answers1

0

I speculate wildly, that you like your Sapatos to be shown in list view, and some property be changed when used performs text edition. You miss (at least) following:

  • Populating list entry with your Sapato data. List entries are reused, and it is correct to inflate layout if convert view is null. But the you will have to set up data from your Sapato in the fields ( move all the findVuewById's outside if, as you have to do it in any case, and populate them)
  • As list views are reused, you have save edited data into your Sapato as soon as edit text loses focus.
Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35