1- /*
2- * Copyright (C) 2014 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
171package com .example .recyclerviewfastscroller .fragment ;
182
193import android .os .Bundle ;
259import android .view .ViewGroup ;
2610
2711import com .example .android .recyclerview .R ;
12+ import com .example .recyclerviewfastscroller .data .ColorDataSet ;
2813import com .example .recyclerviewfastscroller .recyclerview .ColorfulAdapter ;
14+ import com .example .recyclerviewfastscroller .ui .scroller .sectionindicator .title .SectionTitleIndicator ;
2915import com .example .recyclerviewfastscroller .ui .scroller .vertical .VerticalRecyclerViewFastScroller ;
3016
3117/**
3218 * Adapted from sample code that demonstrates the use of {@link RecyclerView} with a {@link LinearLayoutManager}
3319 */
34- public class RecyclerViewWithSectionsFragment extends Fragment {
35-
36- private static final String TAG = "RecyclerViewFragment" ;
37- private static final int DATASET_COUNT = 100 ;
20+ public class RecyclerViewWithSectionIndicatorFragment extends Fragment {
3821
3922 @ Override
4023 public void onCreate (Bundle savedInstanceState ) {
@@ -44,17 +27,23 @@ public void onCreate(Bundle savedInstanceState) {
4427 @ Override
4528 public View onCreateView (LayoutInflater inflater , ViewGroup container ,
4629 Bundle savedInstanceState ) {
47- View rootView = inflater .inflate (R .layout .recycler_view_frag , container , false );
30+ ViewGroup rootView = (ViewGroup ) inflater .inflate (R .layout .recycler_view_with_fast_scroller_section_title_indicator_fragment , container , false );
31+
32+ RecyclerView recyclerView = (RecyclerView ) rootView .findViewById (R .id .recycler_view );
33+ RecyclerView .Adapter adapter = new ColorfulAdapter (new ColorDataSet ());
34+ recyclerView .setAdapter (adapter );
4835
49- RecyclerView recyclerView = ( RecyclerView ) rootView . findViewById ( R . id . recyclerView );
50- VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller ) rootView .findViewById (R .id .fast_scroller );
36+ VerticalRecyclerViewFastScroller fastScroller =
37+ (VerticalRecyclerViewFastScroller ) rootView .findViewById (R .id .fast_scroller );
5138 fastScroller .setRecyclerView (recyclerView );
39+
5240 recyclerView .setOnScrollListener (fastScroller .getOnScrollListener ());
5341
54- setRecyclerViewLayoutManager (recyclerView );
42+ SectionTitleIndicator sectionTitleIndicator =
43+ (SectionTitleIndicator ) rootView .findViewById (R .id .fast_scroller_section_title_popup );
44+ fastScroller .setSectionIndicator (sectionTitleIndicator );
5545
56- RecyclerView .Adapter adapter = new ColorfulAdapter (getDummyDataSet ());
57- recyclerView .setAdapter (adapter );
46+ setRecyclerViewLayoutManager (recyclerView );
5847
5948 return rootView ;
6049 }
@@ -77,14 +66,4 @@ public void setRecyclerViewLayoutManager(RecyclerView recyclerView) {
7766 recyclerView .scrollToPosition (scrollPosition );
7867 }
7968
80- /**
81- * Generates Strings for RecyclerView's adapter. This data would usually come from somewhere...
82- */
83- private String [] getDummyDataSet () {
84- String [] data = new String [DATASET_COUNT ];
85- for (int i = 0 ; i < DATASET_COUNT ; i ++) {
86- data [i ] = "This is element #" + i ;
87- }
88- return data ;
89- }
9069}
0 commit comments