*bump* ;-) On Sun, Jan 11, 2009 at 7:10 PM, Mariano Kamp <mariano.k...@gmail.com>wrote:
> Hi, > I have a performance problem in a ListView. The problem seems to be that > it takes too long to setup each individual row. It scrolls very, very > painfully slow, because of that. > > The actual code renders an Entry differently depending on the read state > and if it is changed. When not using this code and just plainly called > setText() on the TextViews it is reasonable fast. Also the content is HTML. > > Am I doing something terribly wrong here? > > > <?xml version="1.0" encoding="utf-8"?> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" > android:layout_width="fill_parent" android:layout_height="wrap_content"> > > <TextView android:id="@+id/feed_title" android:layout_width="fill_parent" > android:layout_height="wrap_content" android:textSize="11sp" > android:paddingTop="3px" /> > <TextView android:id="@+id/entry_title" android:layout_width="fill_parent" > android:layout_height="wrap_content" android:layout_below="@id/feed_title" > android:textSize="15sp" android:paddingBottom="3px" /> > </RelativeLayout> > > class EntryListAdapter extends BaseAdapter { > > [..] > > public View getView(int position, View convertView, ViewGroup parent) { > View rowView = convertView != null ? convertView : activity > .findViewById(R.layout.entry_row); > > if (rowView == null) > rowView = inflater.inflate(R.layout.entry_row, parent, false); > > Entry entry = entries.get(position); > --> slow version > EntryViewHelper.populateEntryView(rowView, entry); > <-- > -- OR -- > --> (somewhat) fast version > TextView entryTitleView = (TextView) rowView.findViewById(R.id.entry_title > ); > TextView feedTitleView = (TextView) rowView.findViewById(R.id.feed_title); > > > feedTitleView.setText(entry.getFeedTitle()); > entryTitleView.setText(entry.getTitle()); > <-- > return rowView; > } > } > > class EntryViewHelper { > [..] > > static void populateEntryView(View view, Entry entry) { > > TextView entryTitleView = (TextView) view > .findViewById(R.id.entry_title); > TextView feedTitleView = (TextView) view.findViewById(R.id.feed_title); > > feedTitleView.setText(U.renderTitleToSpannedString( > entry.getFeedTitle(), entry.getFeedTitleType())); > entryTitleView.setText(U.renderTitleToSpannedString(entry.getTitle(), > entry.getTitleType())); > > int style = Typeface.NORMAL; > if (!entry.isRead()) > style |= Typeface.BOLD; > if (entry.isReadStatePending()) > style |= Typeface.ITALIC; > > entryTitleView.setText(U.renderTitleToSpannedString(entry.getTitle(), entry > .getTitleType())); > feedTitleView.setText(U.renderTitleToSpannedString( > entry.getFeedTitle(), entry.getFeedTitleType())); > > entryTitleView.setTypeface(Typeface.DEFAULT, style); > } > } > > .. > import android.text.Html; > import android.text.Spanned; > import android.text.SpannedString; > .. > class U { > static Spanned renderTitleToSpannedString(String titleString, > String titleType) { > Spanned title = null; > if ("html".equals(titleType) || "xhtml".equals(titleType)) > title = Html.fromHtml(titleString); > else > title = new SpannedString(titleString); > return title; > } > } > > Btw. I re-use the convert view etc. The performance degradation only > happens when I style the output. > > Cheers, > Mariano > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---