1 /* 2 * Copyright (C) 2015 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 package com.android.test.uibench.recyclerview; 17 18 import android.support.v7.widget.RecyclerView; 19 import android.view.LayoutInflater; 20 import android.view.View; 21 import android.view.ViewGroup; 22 import android.widget.TextView; 23 24 public class RvArrayAdapter extends RecyclerView.Adapter<RvArrayAdapter.ViewHolder> { 25 private String[] mDataSet; 26 private LayoutInflater mLayoutInflater; 27 28 public static class ViewHolder extends RecyclerView.ViewHolder { 29 private final TextView mTextView; 30 31 public ViewHolder(View v) { 32 super(v); 33 mTextView = (TextView) v.findViewById(android.R.id.text1); 34 } 35 36 public TextView getTextView() { 37 return mTextView; 38 } 39 } 40 41 public RvArrayAdapter(String[] dataSet) { 42 mDataSet = dataSet; 43 } 44 45 @Override 46 public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 47 if (mLayoutInflater == null) { 48 mLayoutInflater = LayoutInflater.from(viewGroup.getContext()); 49 } 50 View v = mLayoutInflater.inflate(android.R.layout.simple_list_item_1, viewGroup, false); 51 52 return new ViewHolder(v); 53 } 54 55 @Override 56 public void onBindViewHolder(ViewHolder viewHolder, final int position) { 57 viewHolder.getTextView().setText(mDataSet[position]); 58 } 59 60 @Override 61 public int getItemCount() { 62 return mDataSet.length; 63 } 64 } 65