我正在为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
的项目?