1 /* 2 * Copyright (C) 2017 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 androidx.wear.widget; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.view.ViewGroup; 22 import android.widget.TextView; 23 24 import androidx.recyclerview.widget.RecyclerView; 25 import androidx.wear.test.R; 26 27 public class WearableRecyclerViewTestActivity extends Activity { 28 @Override onCreate(Bundle savedInstanceState)29 protected void onCreate(Bundle savedInstanceState) { 30 super.onCreate(savedInstanceState); 31 setContentView(R.layout.wearable_recycler_view_basic); 32 WearableRecyclerView wrv = findViewById(R.id.wrv); 33 wrv.setLayoutManager(new WearableLinearLayoutManager(this)); 34 wrv.setAdapter(new TestAdapter()); 35 } 36 37 private class ViewHolder extends RecyclerView.ViewHolder { 38 TextView mView; ViewHolder(TextView itemView)39 ViewHolder(TextView itemView) { 40 super(itemView); 41 mView = itemView; 42 } 43 } 44 45 private class TestAdapter extends WearableRecyclerView.Adapter<ViewHolder> { 46 47 @Override onCreateViewHolder(ViewGroup parent, int viewType)48 public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 49 TextView view = new TextView(parent.getContext()); 50 view.setLayoutParams(new RecyclerView.LayoutParams(200, 50)); 51 return new ViewHolder(view); 52 } 53 54 @Override onBindViewHolder(ViewHolder holder, int position)55 public void onBindViewHolder(ViewHolder holder, int position) { 56 holder.mView.setText("holder at position " + position); 57 holder.mView.setTag(position); 58 } 59 60 @Override getItemCount()61 public int getItemCount() { 62 return 100; 63 } 64 } 65 } 66