mathew-kurian / TextJustify-Android

:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0
https://github.com/bluejamesbond/TextJustify-Android/wiki
Apache License 2.0
1.86k stars 370 forks source link

Setting text with spannable, wont update unless i click and drag on textview #61

Closed broakenmedia closed 9 years ago

broakenmedia commented 9 years ago
private Spannable highlightString(String original, String search) {
    String rep = original;
    String newS = rep.replace(search, "<font color='red'>" + search + "</font>");
    ArticleBuilder amb = new ArticleBuilder();
    amb.append(
            newS
            , false, new RelativeSizeSpan(1f), new JustifiedSpan()
    );
    return amb;
    }

I am setting the text of my document view using the above which results in:

http://puu.sh/fepY7/a2edfbad2a.png

However, when i select a new line to highlight, NOTHING happens, setting the text view to ANY content, normal spannable string or otherwise, the view refuses to update, the only way i can get it to show the new value is to tap and drag on the view, how peculiar?

Thanks!

mathew-kurian commented 9 years ago

@xbroak Just call documentView.requestLayout(). This was done in order to optimize when to initiate justification. In other words, you can do batch changes to the settings and then just call requestLayout or invalidate depending on whether you changed any metric affecting features or just some basic color settings respectively.

broakenmedia commented 9 years ago

I tried that! Nothing.

------ Original Message ------ From: "Mathew Kurian" notifications@github.com To: "bluejamesbond/TextJustify-Android" TextJustify-Android@noreply.github.com Cc: "Joe Scott" broak@live.co.uk Sent: 30/01/2015 18:38:50 Subject: Re: [TextJustify-Android] Setting text with spannable, wont update unless i click and drag on textview (#61)

@xbroak Just call documentView.requestLayout().

— Reply to this email directly or view it on GitHub.

mathew-kurian commented 9 years ago

Which version are you running? And can you paste some more of your code here i.e. your layout and activity (portions relating to this lib).

broakenmedia commented 9 years ago

Latest

------ Original Message ------ From: "Mathew Kurian" notifications@github.com To: "bluejamesbond/TextJustify-Android" TextJustify-Android@noreply.github.com Cc: "Joe Scott" broak@live.co.uk Sent: 30/01/2015 18:41:27 Subject: Re: [TextJustify-Android] Setting text with spannable, wont update unless i click and drag on textview (#61)

Which version?

— Sent from Mailbox

On Fri, Jan 30, 2015 at 12:40 PM, Joe Scott notifications@github.com wrote:

I tried that! Nothing. ------ Original Message ------ From: "Mathew Kurian" notifications@github.com To: "bluejamesbond/TextJustify-Android" TextJustify-Android@noreply.github.com Cc: "Joe Scott" broak@live.co.uk Sent: 30/01/2015 18:38:50 Subject: Re: [TextJustify-Android] Setting text with spannable, wont update unless i click and drag on textview (#61)

@xbroak Just call documentView.requestLayout().

— Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:

https://github.com/bluejamesbond/TextJustify-Android/issues/61#issuecomment-72248741 — Reply to this email directly or view it on GitHub.

broakenmedia commented 9 years ago

Weird, i am seeing different responses in the email notifications! how strange.

compile 'com.github.bluejamesbond:textjustify-android:2.0.8'

That's the version, just fyi

broakenmedia commented 9 years ago

The only code is the documentview example on the wiki and the code i've pasted in my original post :)

mathew-kurian commented 9 years ago

I think I know the issue. I don't have a computer near me. Try calling documentView.invalidateCache() right after you set the updated text. So, it should look like this.

documentView.setText(newText);
documentView.invalidateCache();
documentView.requestLayout();
broakenmedia commented 9 years ago

Hi, sorry to respond so late, it seems that 'invalidateCache' is not a defined method/public

broakenmedia commented 9 years ago

Just tried using destroyCache(); in its place, which does actually make it update! just only the first time, when attempting to set the text a second time, it reverts back to the old behaviour!

broakenmedia commented 9 years ago

Well. It seems that it's as simple as calling 'invalidate' after setting the text. Seems to update as desired now, very peculiar though?

mathew-kurian commented 9 years ago

@xbroak You don't need to do any of that anymore. Just set the text and it should change. Use version 2.0.9

broakenmedia commented 9 years ago

I'm afraid, it is not fixed!

broakenmedia commented 9 years ago

Seems to be doing it all over again for some reason, my fix just stopped working.

When highlighting text, it highlights the wrong words! ( even those logging the actual text + html shows the correct setup) and the only way to fix it is to do the familiar drag to update)

mathew-kurian commented 9 years ago

Which version are you using?

broakenmedia commented 9 years ago

(Just updated the comment above)

I'm using the latest (2.1.0)

mathew-kurian commented 9 years ago

I think you should revert back to tge last working version I'll notify you when I can confirm the sokution.

broakenmedia commented 9 years ago

The weird thing is, even moving back to the old version seems to be doing it now. I literally changed nothing.

broakenmedia commented 9 years ago

I have a feeling i was just getting lucky before and the problem only happens at random.

mathew-kurian commented 9 years ago

If you can post a video. That would be the best!

— Sent from Mailbox

On Wed, Feb 4, 2015 at 2:24 PM, Joe Scott notifications@github.com wrote:

I have a feeling i was just getting lucky before and the problem only happens at random.

Reply to this email directly or view it on GitHub: https://github.com/bluejamesbond/TextJustify-Android/issues/61#issuecomment-72931618

sigrlami commented 9 years ago

@xbroak you should try to call invalidate() on your DocumentView, I've got almost same problem and this helped. Somehow requestLayout() doesn't force to redraw view

Edonfreiner commented 7 years ago

Is there any fix for this yet I am trying to change the inline background for the DocumentView