@@ -28,7 +28,8 @@ public class DemoMenuActivity extends Activity {
2828
2929 };
3030
31- private MyAdapter secondAdapter ;
31+ private MyAdapter secondAdapter ;
32+ private View lastFocus = null ;
3233
3334 @ Override
3435 protected void onCreate (Bundle savedInstanceState ) {
@@ -42,33 +43,40 @@ protected void onCreate(Bundle savedInstanceState) {
4243 RecyclerView firstRecyclerView = (RecyclerView ) findViewById (R .id .firstRecyclerView );
4344 RecyclerView secondRecyclerView = (RecyclerView ) findViewById (R .id .secondRecyclerView );
4445
45- GridLayoutManager layoutManager = new GridLayoutManager (this ,1 );
46+ GridLayoutManager layoutManager = new GridLayoutManager (this , 1 );
4647 layoutManager .setOrientation (LinearLayoutManager .VERTICAL );
4748 firstRecyclerView .setLayoutManager (layoutManager );
4849 firstRecyclerView .setFocusable (false );
4950
5051
51-
52- GridLayoutManager layoutManager2 = new GridLayoutManager (this ,1 );
52+ GridLayoutManager layoutManager2 = new GridLayoutManager (this , 1 );
5353 layoutManager2 .setOrientation (LinearLayoutManager .VERTICAL );
5454 secondRecyclerView .setLayoutManager (layoutManager2 );
5555 secondRecyclerView .setFocusable (false );
5656
5757
58- secondAdapter = new MyAdapter (this ,new String []{},R .layout .item_menu );
58+ secondAdapter = new MyAdapter (this , new String []{}, R .layout .item_menu_sub );
5959 secondRecyclerView .setAdapter (secondAdapter );
6060
6161
6262 // 创建Adapter,并指定数据集
63- MyAdapter adapter = new MyAdapter (this , mCategory ,R .layout .item_menu ,new View .OnFocusChangeListener (){
64-
63+ MyAdapter adapter = new MyAdapter (this , mCategory , R .layout .item_menu , new View .OnFocusChangeListener () {
6564 @ Override
6665 public void onFocusChange (View v , boolean hasFocus ) {
67- if (hasFocus ) {
66+ if (hasFocus ) {
6867 int pos = (int ) v .getTag ();
6968 secondAdapter .setData (mDatas [pos ]);
7069 secondAdapter .notifyDataSetChanged ();
71- Log .d ("tt" , "onFocusChange===>" +pos );
70+ Log .d ("tt" , "onFocusChange===>" + pos );
71+
72+ if (lastFocus !=null )
73+ lastFocus .setBackgroundResource (R .drawable .list_item_shape );
74+ lastFocus = v ;
75+ v .setBackgroundResource (R .drawable .shape );
76+
77+
78+ } else {
79+ //v.setBackgroundColor(Color.RED);
7280 }
7381 }
7482 });
@@ -81,11 +89,7 @@ public void onFocusChange(View v, boolean hasFocus) {
8189 border .attachTo (secondRecyclerView );
8290
8391
84-
8592 }
8693
8794
88-
89-
90-
9195}
0 commit comments