1

I showed a list of Items using Recycler View on Android TV. But my list is not scrolling and has focused on it. Kindly help me to resolve this issue.

private void initRecyclerView(){
    ArrayList<String> categoryList = (ArrayList<String>) getIntent().getSerializableExtra("categoryList"); 
    RecyclerView recyclerView=(RecyclerView) findViewById(R.id.categoryRecyclerView);
    RecyclerViewAdapter adapter=new RecyclerViewAdapter(this,categoryList);
    System.out.println("investmentRecyclerView array: " + categoryList);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
Abhinava B N
  • 165
  • 1
  • 12
Omar
  • 11
  • 2

3 Answers3

1

Set focusable=true for Item's layout :

Ex. list_item.xml is RecycerlView's item :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/item_selector"
    android:focusable="true">
    <TextView
        android:id="@+id/topic"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:textColor="#ffffff"
        android:gravity="center"/>
</LinearLayout>

To see if its focused or not add this sector as drawable, and add images accordingly :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/black" android:state_pressed="true"/>
    <item android:drawable="@color/black" android:state_selected="true"/>
    <item android:drawable="@color/black" android:state_focused="true"/>

    <item android:drawable="@color/lightblue"></item>
</selector>
NehaK
  • 2,639
  • 1
  • 15
  • 31
1

You have to use VerticalGridView and HorizontalGridView from Leanback SDK instead of RecyclerView

<androidx.leanback.widget.HorizontalGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:lb="http://schemas.android.com/apk/res-auto"
android:id="@+id/row_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
lb:rowHeight="wrap_content"
style="?attr/rowHorizontalGridStyle" />
0

Thanks for the responce. This is my XML code.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:id="@+id/parent_layout"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/countries_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="40dp"
        android:textSize="17sp"
        android:text="Canada" />
</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   <androidx.recyclerview.widget.RecyclerView
       android:id="@+id/recyclerView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:focusable="true"
       android:scrollbars="vertical"></androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
Omar
  • 11
  • 2