I am developing app for Android TV
. In app there is a fragment layout that has four ImageView
in LinearLayout
horizontal direction and a RecyclerView
that is below on LinearLayout
. When I launch app and navigate through DPAD
control then RecyclerView
navigate up and down. Requirement is that when fragment launch by default first ImageView
of LinearLayout
would be selected. After when we press right button of DPAD then next ImageView
would be select. When we press down key then focus will move on RecyclerView
. When focus will on RecyclerView
first child and we press Up key then focus move on first Imageview
of LinearLayout
.
I have also use imageview.requestFocus() but it is not working. Please help me.
Below is my layout file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/home_fragment_menu_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp">
<ImageView
android:id="@+id/img_playall"
style="@style/home_fragment_menu"
android:src="@drawable/play_all"
android:focusable="true"
android:focusableInTouchMode="true"/>
<ImageView
android:id="@+id/img_trending"
style="@style/home_fragment_menu"
android:src="@drawable/trending"/>
<ImageView
android:id="@+id/img_search"
style="@style/home_fragment_menu"
android:src="@drawable/search"/>
<ImageView
android:id="@+id/img_setting"
style="@style/home_fragment_menu"
android:src="@drawable/settings"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/home_fragment_menu_container"
android:layout_marginLeft="45dp"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/vertical_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</RelativeLayout>
Below is fragment.java file
public class HomeFragment extends Fragment {
private static final String TAG = "HomeFragment";
ImageView playAllImage, trendingImage, searchImage, settingImage;
Context context;
RecyclerView verticalList;
ArrayList<ArrayList<VideoContentModel>> categoriesVideoList;
ArrayList<CategoryModel> categoryDataList;
public static HomeFragment newInstance(Context context, ArrayList<ArrayList<VideoContentModel>> categoriesVideoList,
ArrayList<CategoryModel> categoryDataList){
HomeFragment fragment = new HomeFragment();
fragment.context = context;
fragment.categoriesVideoList = categoriesVideoList;
fragment.categoryDataList = categoryDataList;
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.home_fragment_layout, container, false);
playAllImage = (ImageView)view.findViewById(R.id.img_playall);
trendingImage = (ImageView)view.findViewById(R.id.img_trending);
searchImage = (ImageView)view.findViewById(R.id.img_search);
settingImage = (ImageView)view.findViewById(R.id.img_setting);
playAllImage.requestFocus();
verticalList = (RecyclerView)view.findViewById(R.id.vertical_recyclerview);
verticalList.setHasFixedSize(true);
verticalList.setLayoutManager(new LinearLayoutManager(context));
CatListVerticalAdapter adapter = new CatListVerticalAdapter(context,categoriesVideoList,categoryDataList);
verticalList.setAdapter(adapter);
verticalList.clearFocus();
//
if(playAllImage.hasFocus())
Log.i(TAG,"play all has focus");
else
Log.i(TAG,"===playall has not focus");
return view;
}
How we navigate through DPAD above requirement? Please help me..