|
| 1 | +package org.evilbinary.tv; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.support.v7.widget.GridLayoutManager; |
| 6 | +import android.support.v7.widget.LinearLayoutManager; |
| 7 | +import android.support.v7.widget.RecyclerView; |
| 8 | +import android.util.Log; |
| 9 | +import android.view.View; |
| 10 | + |
| 11 | +import org.evilbinary.tv.widget.BorderView; |
| 12 | + |
| 13 | +/** |
| 14 | + * 作者:evilbinary on 4/10/16. |
| 15 | + * 邮箱:rootdebug@163.com |
| 16 | + */ |
| 17 | +public class DemoMenuActivity extends Activity { |
| 18 | + private BorderView border; |
| 19 | + |
| 20 | + |
| 21 | + private String mCategory[] = new String[]{"全部频道", "美食", "休闲娱乐", "购物"}; |
| 22 | + //二级列表数据 |
| 23 | + private String mDatas[][] = new String[][]{ |
| 24 | + new String[]{"全部美食", "江浙菜", "川菜", "粤菜", "湘菜"}, |
| 25 | + new String[]{"全部休闲娱乐", "咖啡厅", "酒吧", "茶馆", "KTV"}, |
| 26 | + new String[]{"全部购物", "综合商场", "服饰鞋包", "运动户外"}, |
| 27 | + new String[]{"全部休闲娱乐", "咖啡厅", "酒吧", "茶馆"}, |
| 28 | + |
| 29 | + }; |
| 30 | + |
| 31 | + private MyAdapter secondAdapter; |
| 32 | + |
| 33 | + @Override |
| 34 | + protected void onCreate(Bundle savedInstanceState) { |
| 35 | + super.onCreate(savedInstanceState); |
| 36 | + setContentView(R.layout.demo_menu); |
| 37 | + |
| 38 | + |
| 39 | + border = new BorderView(this); |
| 40 | + border.setBackgroundResource(R.drawable.border_red); |
| 41 | + |
| 42 | + RecyclerView firstRecyclerView = (RecyclerView) findViewById(R.id.firstRecyclerView); |
| 43 | + RecyclerView secondRecyclerView = (RecyclerView) findViewById(R.id.secondRecyclerView); |
| 44 | + |
| 45 | + GridLayoutManager layoutManager = new GridLayoutManager(this,1); |
| 46 | + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); |
| 47 | + firstRecyclerView.setLayoutManager(layoutManager); |
| 48 | + firstRecyclerView.setFocusable(false); |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + GridLayoutManager layoutManager2 = new GridLayoutManager(this,1); |
| 53 | + layoutManager2.setOrientation(LinearLayoutManager.VERTICAL); |
| 54 | + secondRecyclerView.setLayoutManager(layoutManager2); |
| 55 | + secondRecyclerView.setFocusable(false); |
| 56 | + |
| 57 | + |
| 58 | + secondAdapter=new MyAdapter(this,new String[]{},R.layout.item_menu); |
| 59 | + secondRecyclerView.setAdapter(secondAdapter); |
| 60 | + |
| 61 | + |
| 62 | + // 创建Adapter,并指定数据集 |
| 63 | + MyAdapter adapter = new MyAdapter(this, mCategory,R.layout.item_menu,new View.OnFocusChangeListener(){ |
| 64 | + |
| 65 | + @Override |
| 66 | + public void onFocusChange(View v, boolean hasFocus) { |
| 67 | + if(hasFocus) { |
| 68 | + int pos = (int) v.getTag(); |
| 69 | + secondAdapter.setData(mDatas[pos]); |
| 70 | + secondAdapter.notifyDataSetChanged(); |
| 71 | + Log.d("tt", "onFocusChange===>"+pos); |
| 72 | + } |
| 73 | + } |
| 74 | + }); |
| 75 | + // 设置Adapter |
| 76 | + firstRecyclerView.setAdapter(adapter); |
| 77 | + firstRecyclerView.scrollToPosition(0); |
| 78 | + |
| 79 | + border.getEffect().setScalable(false); |
| 80 | + border.attachTo(firstRecyclerView); |
| 81 | + border.attachTo(secondRecyclerView); |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +} |
0 commit comments