1 /* 2 * Copyright (C) 2019 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 17 package com.android.car.themeplayground; 18 19 import android.os.Bundle; 20 21 import androidx.recyclerview.widget.LinearLayoutManager; 22 import androidx.recyclerview.widget.RecyclerView; 23 24 import java.util.ArrayList; 25 26 /** 27 * Activity that shows RecyclerView example with placeholder data. 28 */ 29 public class RecyclerViewSamples extends AbstractSampleActivity { 30 31 private static final int DATA_TO_GENERATE = 15; 32 33 private final ArrayList<String> mData = new ArrayList<>(); 34 35 @Override onCreate(Bundle savedInstanceState)36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 Utils.onActivityCreateSetTheme(this); 39 setContentView(R.layout.recycler_view_samples); 40 RecyclerView recyclerView = findViewById(R.id.list); 41 recyclerView.setLayoutManager(new LinearLayoutManager(this)); 42 43 RecyclerViewAdapter adapter = new RecyclerViewAdapter(generatePlaceholderData()); 44 recyclerView.setAdapter(adapter); 45 } 46 generatePlaceholderData()47 private ArrayList<String> generatePlaceholderData() { 48 for (int i = 0; i <= DATA_TO_GENERATE; i++) { 49 mData.add("data" + i); 50 } 51 return mData; 52 } 53 54 } 55