[Android TV Button responds to]listview's TextView the problem of failure under mouse control

Source: Internet
Author: User

Problem: Remote control button selected options have a marquee effect, but the mouse event, there is no marquee effect

Solving process: Rewrite a class to inherit TextView, always get focus, no. Even if I onhoverlistener inside Onhover and got the focus on TextView, it still doesn't work.

Workaround: Finally rewrite a class to inherit TextView, get focus forever, and call setselected (true) on TextView.

public class Marqueetextview extends TextView {public    marqueetextview (Context con) {        super (con);    }    Public Marqueetextview (context context, AttributeSet Attrs) {        Super (context, attrs);    }    Public Marqueetextview (context context, AttributeSet attrs, int defstyle) {        Super (context, attrs, Defstyle);    }    @Override Public    boolean isFocused () {        return true;    }    @Override    protected void Onfocuschanged (Boolean focused, int direction,            Rect previouslyfocusedrect) {    }}

    <com.jrm.localmm.ui.view.marqueetextview        android:id= "@+id/listnametextview"        android:layout_width= " Wrap_content "        android:layout_height=" wrap_content "        android:ellipsize=" marquee "        android:gravity=" Left "        android:layout_marginleft=" 2dip "        android:marqueerepeatlimit=" Marquee_forever "        android: Singleline= "true"        android:textcolor= "@android: Color/white"        android:textsize= "15sp" >    </ Com.jrm.localmm.ui.view.marqueetextview>



Holder.settingOptionTextView.setSelected (TRUE);


In addition summarizes the next under an TV mouse, remote key events:

First of all, for selector, only the remote button under TV can trigger all events: focus,selected,press

<?xml version= "1.0" encoding= "UTF-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "><!--no focus Yiwen--><item android:state_focused=" false "android:state_selected=" false "android:state _pressed= "false" android:drawable= "@android: color/transparent"/><item android:state_focused= "false" Android : State_selected= "true" android:state_pressed= "false" android:drawable= "@drawable/list_foucs"/><!--focus Yiwen-- ><item android:state_focused= "true" android:state_selected= "false" Android:state_pressed= "false" Android: drawable= "@drawable/list_foucs"/><item android:state_focused= "true" android:state_selected= "true" Android: State_pressed= "false" android:drawable= "@drawable/list_foucs"/><!--Press down Yiwen--><item Android:state_ Pressed= "true" android:drawable= "@drawable/list_foucs"/></selector>

The press event can be triggered by the mouse only when clicked.

As for how to imitate the button event under mouse control to select an item, the background image changes, can only indirectly by setting the item background image to achieve

    Refresh the focus state of a ListView item public    void refreshitemfocusstate (int index) {        //TODO auto-generated m Ethod stub        log.d (TAG, "refreshitemfocusstate index =" +index);        Currentselecteditemview =  Listview.getchildat (index);        if (isenterlistviewlocation) {            if (Oldselecteditemview! = null)                Oldselecteditemview.setbackgroundresource ( R.drawable.button_normal);            if (Currentselecteditemview! = null)                Currentselecteditemview.setbackgroundresource (R.DRAWABLE.LIST_FOUCS);            Oldselecteditemview = Currentselecteditemview;        }    }


[Android TV Button responds to]listview's TextView the problem of failure under mouse control

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.