Dpad控制水平Recyclerview

时间:2016-09-14 07:47:47

标签: android android-recyclerview

我正在为android TV制作应用。我需要一个水平Recyclerview,可以使用DPAD控制器滚动,在Recyclerview获取DPAD时,使用DPAD右键和Recyclerview左键选择 public class Main2Activity extends AppCompatActivity { String A[]= {"A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A", "E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E","E"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.recylcer_row); RecyclerView recyclerView = (RecyclerView)findViewById(R.id.innerRview); InnerAdapter innerAdapter = new InnerAdapter(this,A); recyclerView.requestFocus(); recyclerView.setAdapter(innerAdapter); } } 项焦点。但它不起作用。以下是我的代码

活动代码

public class InnerAdapter extends RecyclerView.Adapter<InnerAdapter.MyViewHolder> {
    Context context;
    String arrayList[];

    public InnerAdapter(Context context, String[] arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.inner_row, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.textView.setText(arrayList[position]);

    }

    @Override
    public int getItemCount() {
        return arrayList.length;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        public MyViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.localText);


        }

    }
}

适配器代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    >

    <android.support.v7.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/innerRview"
        android:orientation="horizontal"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        android:descendantFocusability="afterDescendants"/>

</LinearLayout>

布局xml文件

Recyclerview

如何借助Dpad键选择CASE的项目?

0 个答案:

没有答案