Jagdish Bhavsar
Jagdish Bhavsar

Reputation: 34

Listview has Arrayadpater with edittext

I have single view layout with edit text and image. To display data in listview i am using arrayadapter . While entering value in Edit text in first row. The data gets repeated to another row in listview . How can i resolve this ?

View rowView = null;
    try {
        if (convertView == null) {
            //inflating view.
            rowView = 
 inflater.inflate(R.layout.list_single_view,null,false); 

        }
        else 
        {
            //Setting view if layout is already implemented.
            rowView = convertView;
        }

        imageView = (ImageView)  
rowView.findViewById(R.id.iv_activity_image_single);

        //Facing issue here in editText . The entered text gets repeated 
        et_image_name = (EditText)    
rowView.findViewById(R.id.txt_user_notes);
        et_image_description = (EditText) 
rowView.findViewById(R.id.txt_user_description);

        //Loading image using universal image loader to imageView
        if (equipmentPicturesList.get(position) != null) {
            Constant.imageLoader.displayImage("file:///" + 
equipmentPicturesList.get(position).toString(), imageView, Constant.options,
                    new SimpleImageLoadingListener());
        }
        else {
            imageView.setBackgroundResource(R.drawable.ic_launcher);
        }
}
    catch (Exception e) {
        Logger.loadStackTrace(e);
    }

    return rowView;

Upvotes: 0

Views: 41

Answers (1)

Xaver Kapeller
Xaver Kapeller

Reputation: 49817

The EditText messes with the focus of whatever layout it is in. That can be a little tricky by itself, but in a ListView it causes all sorts of problems. But there is a way around that, it will work if you put the EditText inside the footer or header of the ListView with addHeaderView or addFooterView. The reason that it works in the header or footer is that the header and footer views are not recycled by the ListView. Alternatively you can call setHasTransientState() on the EditText to prevent it from being recycled even as a normal view inside the ListView.

But beware that turning off the view recycling - especially if you do it for multiple views - can impact performance and scrolling speed of the ListView.

Upvotes: 1

Related Questions