I only loaded the data after seeing the buttons of the JD TV app to get the focus. I didn’t find a good statement on the Internet before, so I realized it and recorded it for subsequent learning.
Mainly, after the button gets the focus, the timer is initialized and the timer delays loading data by 500ms. If the focus is lost, canceling the timer will be OK. In fact, the principle is very simple. Here is an effect I achieved.
package .; import ; import .; import .; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; /** * Created by yzq on 2017/5/8 */ public class ButtonAdapter extends <> { private List<DepartmentParam> mDepartmentList = new ArrayList<>(); private LayoutInflater mInflater; private Context mContext; private boolean mIsLostFocus = false; private LinearLayoutManager mLinearLayoutManager; private RecyclerView mRecyclerView; private TimerTask mTimerTask; private Timer mTimer; private boolean isLoadData = true; public ButtonAdapter(Context context) { super(); = context; mInflater = (context); } public void setLayoutManager(LinearLayoutManager linearLayoutManager, RecyclerView re) { mLinearLayoutManager = linearLayoutManager; mRecyclerView = re; } public void setDepartmentList(List list) { mDepartmentList = list; } public void setFocus(boolean isFocus) { mIsLostFocus = isFocus; } public void setIsLoadData(boolean isLoadData) { = isLoadData; } public void clear() { (); } @Override public int getItemCount() { return (); } @Override public void onBindViewHolder(final MyViewHolder holder, final int position) { ((position).GetDeptName()); (true); } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = (.list_class_item, parent, false); MyViewHolder holder = new MyViewHolder(view); return holder; } class MyViewHolder extends { MagicTextView tv; RelativeLayout mOuterBgRL; public MyViewHolder(final View view) { super(view); param = () (); = .WRAP_CONTENT; = .MATCH_PARENT; (); tv = (MagicTextView) (.class_name); mOuterBgRL = (RelativeLayout) (.rl_class_outer_bg); (new () { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { (.p2p_select); if (isLoadData) { mTimerTask = new TimerTask() { @Override public void run() { int iPosition = getAdapterPosition(); DepartmentParam departmentParam = (iPosition); (.P2P_SELECTION_DOCTOR_CLASS, iPosition, departmentParam); } }; mTimer = new Timer(); (mTimerTask, 500); } } else { clearTimer(); if (mIsLostFocus) { (.p2p_unselect); } } } }); (new () { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (() == KeyEvent.ACTION_DOWN) { int mCurrentSelectPosition = getAdapterPosition(); int mDepartmentCount = (); ("mCurrentSelectPosition>>>>>>>>", mCurrentSelectPosition + "----" + mDepartmentCount); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: setIsLoadData(true); setFocus(true); if (mCurrentSelectPosition == (())) { (-400, 0); } View view1 = (mCurrentSelectPosition - 1); if (view1 != null) { setViewFocus((.class_name)); } return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (mCurrentSelectPosition == mDepartmentCount - 1) { return true; } setIsLoadData(true); setFocus(true); if (mCurrentSelectPosition == (())) { (400, 0); } View view = (mCurrentSelectPosition + 1); if (view != null) { setViewFocus((.class_name)); } return true; case KeyEvent.KEYCODE_BACK: break; case KeyEvent.KEYCODE_DPAD_UP: break; case KeyEvent.KEYCODE_DPAD_DOWN: setFocus(false); (.p2p_key_down); break; } } return false; } }); } } public void setViewFocus(View view) { (true); (true); (); (); } private void clearTimer() { if (mTimer != null) { (); } if (mTimerTask != null) { (); } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.