Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old November 29th, 2010, 08:29 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2010
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom ListView repeats itself when scrolling

I have a custom listview that pulls from an array, however when I reach a point that I have to scroll down to see more items, the items start to repeat themselves. According to the array, the items are fine and not repeating themselves, it looks like it's just the ListAdapter. Any help is greatly appreciated. I think the getView is really the only problem, but if you need other parts of the code, let me know.
Code:
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.list_item, parent, false);
			holder = new ViewHolder();
			holder.title = (TextView) convertView.findViewById(R.id.row_title);
			holder.summary = (TextView) convertView.findViewById(R.id.row_summary);
			holder.url = (TextView) convertView.findViewById(R.id.row_link);
			convertView.setTag(holder);
			String item = CurbAlert.listings[position];
			item = item.replace("<br>", "");
			String title = item.substring(item.indexOf("<title>") + 16, item.indexOf("</title>") - 3);
			String summary = item.substring(item.indexOf("<description>") + 22, item.indexOf("</description>") - 3);
			if (summary.length() > 100) { summary = summary.substring(0, 100); summary += "..."; }
			holder.title.setText(title);
			holder.summary.setText(summary);
			holder.url.setText(item.substring(item.indexOf("<link>") + 6, item.indexOf("</link>")));
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}

xfj37dsj3b is offline  
Reply With Quote
sponsored links
Old November 30th, 2010, 09:56 PM   #2 (permalink)
New Member
 
Join Date: Aug 2010
Posts: 12
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 1 Time in 1 Post
Default

The first time through the getView method the convertView is empty, but when you scroll, it reuses that convertView (it creates just enough convertViews to fill the listview's space). So, your else statement is the only thing that gets executed and it sends that same convertView back out with the data that was in it before.

To fix it; it looks like you need to move everything after "holder = new ViewHolder();" in the if block to below the if else block.
galth is offline  
Reply With Quote
Old November 30th, 2010, 10:27 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2010
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Awesome that worked, thanks a lot!
xfj37dsj3b is offline  
Reply With Quote
Old January 9th, 2013, 01:27 AM   #4 (permalink)
New Member
 
Join Date: Jan 2013
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Red face Customlistview for repeating items..

Quote:
Originally Posted by xfj37dsj3b View Post
Awesome that worked, thanks a lot!
hey,can you send me the complete source for that repeating items in listview..
thanks in advance..
krupa is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:40 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.