android - TextView.getLineCount() in custom BaseAdapter -


i need show view when mtxttext has maxlinescount or more lines. checked these questions: first , second

what have result in getview method:

mtxttext.settext(html.fromhtml(output)); mtxttext.getviewtreeobserver().addongloballayoutlistener(         new ongloballayoutlistener() {              @suppresswarnings("deprecation")             @override             public void ongloballayout() {                  if (build.version.sdk_int < build.version_codes.jelly_bean) {                     mtxttext.getviewtreeobserver()                             .removeglobalonlayoutlistener(this);                 } else {                     mtxttext.getviewtreeobserver()                             .removeongloballayoutlistener(this);                 }                  if (iscollapseon                         && mtxttext.getlinecount() >= maxlinescount) {                     mtxtexpand.setvisibility(view.visible);                 } else {                     mtxtexpand.setvisibility(view.gone);                 }             }         }); 

but have got interesting results: listener called items in adapter , other items visibility of mtxtexpand set randomly. when scroll list items listener called show wrong views.

thanks help.

i suggest make following changes:

  1. i've never used view tree observer, seems me single view tree observer entire list enough. don't think need separate observer each text view.

  2. since want keep getting layout notifications, don't remove single view tree observer after 1 notification. remove when destroy entire list.

  3. on each layout notification, go on of list cells , check number of lines in each one. can go on them getting of list's children (using getchildat() - not using adapter!). don't need worry concurrency issues because there's single ui thread, getview not run in middle of iteration.

  4. each of list cells contains text view , txt expand. give them specific id's search them given cell view (their parent).

  5. in big iteration (on layout notification), after check each text view, can corresponding txt expand going parent of text view , searching using id.

  6. in observer handler, don't rely on external state variables except maybe getting reference entire list.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -