Tweaking of view.find[TextView](id) does not work

31 views
Skip to first unread message

ales

unread,
Jun 3, 2015, 2:54:21 AM6/3/15
to mac...@googlegroups.com
Hi,
there is a long list of 100 items in my application and after longer scrolling down and up OutOfMemoryException has been raised. Therefore I have modified creating of the item layout so that it is reused after it is not visible (see param "convertView" here: http://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29). After that the memory problems disappeared and everything works fine except of tweaking TextViews.

I did this:
DataSetAdapter is my own class that extends BaseAdapter, it overrides the getView method (override def getView(position: Int, convertView: View, parent: ViewGroup): View)

val adapter = DataSetAdapter(tasks) {
     
(adapter, index, convertView) => {
       
import macroid.contrib.Layouts.VerticalLinearLayout

        val item
= adapter.getRecord[TasksRecord](index)
        val bgcolor
= item.state match {
         
case ActionState.Finished => colorFinished          case ActionState.Started => colorStarted          case _ => colorWhite        }

        val view
= if (convertView != null)
          convertView        
else
          getUi
(l[VerticalLinearLayout](
            w
[TextView] <~ id(Id.name),
            w
[TextView] <~ id(Id.code),
            w
[TextView] <~ id(Id.startTimePlanned),
            w
[TextView] <~ id(Id.taskIssuerName),
            w
[TextView] <~ id(Id.stateName)
         
) <~ padding(left = 5, right = 5, top = 20, bottom = 20) <~ id(Id.row)
         
)

        view
.find[TextView](Id.name) <~ text(item.name) <~ TextTweaks.bold        view.find[TextView](Id.code) <~ text(item.code)
        view
.find[TextView](Id.startTimePlanned) <~ text(item.startTimePlanned) <~ show(item.startTimePlanned != null)
        view
.find[TextView](Id.taskIssuerName) <~ text(item.taskIssuerName)
        view
.find[TextView](Id.stateName) <~ text(item.state.name)

        view
.find[VerticalLinearLayout](Id.row) <~ bgcolor
        view      
}
   
}



Unfortunately
view.find[TextView](Id.name) <~ text(item.name)
does not work, the text of the TextView is not set. Instead of this I have to use "get.get.setText" which is not very elegant and also I cannot use the show tweak and others (conditionally bold the text etc.).

        view.find[TextView](Id.name).get.get.setText(item.name)

Do you know please what's wrong here? Or is there any better approach to reuse the layouts?

Thanks
Ales

Nick Stanchenko

unread,
Jun 3, 2015, 3:04:29 AM6/3/15
to ales, mac...@googlegroups.com

Hi,

Just wrap the tweaking in runUi ;)

Nick

--
You received this message because you are subscribed to the Google Groups "macroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macroid+u...@googlegroups.com.
To post to this group, send email to mac...@googlegroups.com.
Visit this group at http://groups.google.com/group/macroid.
To view this discussion on the web visit https://groups.google.com/d/msgid/macroid/a062c985-453c-495c-bb56-b5bd3669c011%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ales

unread,
Jun 3, 2015, 3:23:40 AM6/3/15
to mac...@googlegroups.com, kahane...@gmail.com
Oh, such a stupid mistake! Thank you very much!
Reply all
Reply to author
Forward
0 new messages