Android TextView SetText () stops highlighting another TextView - workaround?

I am currently playing with marquee function in Android Textview. But there is a problem- I have a layout containing multiple TextViews. On one of them, which shows the name of the music file, I want to apply the highlight function. On the other hand, I keep updating the current track time (every second).

The problem is that every time a TextView, which shows the track time, is updated (setText ()), the selection area of โ€‹โ€‹another TextView is highlighted. I think this is because setTExt () moves the focus in the TextView to which I have to apply the text.

Is there a solution for this?

I used a special class for the marquee text box from this tutorial

Is it possible (maybe a custom class) for another TextView not to "steal" the focus?

Thank!

Hi

+3
source share
6 answers

Marquee is activated when the TextView is set to Enabled (true) or gets focus. Use setEnabled (true) to ensure that other TextViews will not stop the selection when the focus moves.

+4
source

But there is a problem: I have a layout containing several TextViews. I found a solution here: http://androidbears.stellarpc.net/?p=185

You must extend the TextView class and override several methods

@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    if(focused)
       super.onFocusChanged(focused, direction, previouslyFocusedRect);
}



@Override
public void onWindowFocusChanged(boolean focused) {
    if(focused)
       super.onWindowFocusChanged(focused);
}

@Override
public boolean isFocused() {
       return true;
}
+3
source

setEnabled(true) . , , . , , TextView onLayout().

TextView LinearLayout layout_height="wrap_content". TextView, , TextView . , TextView, , , LinearLayout TextView (, , ). LinearLayout ( ) onLayout(), .

, LinearLayout , .

+3

Focus(); TextView, , , TextView . , , .

TextView.requestFocus ()

+1
source

See my answer here: fooobar.com/questions/1427412 / ...

The idea is this:

  • to fix width and height programmatically
  • to setselected
  • Override TextView to fix focus issues.
+1
source

You can just crop the TextView region with LinearLayout

0
source

Source: https://habr.com/ru/post/1791588/


All Articles