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;  

}

6
  • 2
    Do you mean that you have edit text inside every list item ?
    – Lukap
    Jan 20, 2012 at 12:24
  • I don't really understand the question...can you post some code?
    – iaindownie
    Jan 20, 2012 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. Jan 20, 2012 at 12:47
  • I posted the method getView(). Jan 20, 2012 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, 2012 at 0:43

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.