1 /* 2 * Copyright 2021 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.navigation.testapp 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import android.widget.TextView 23 import androidx.recyclerview.widget.RecyclerView 24 25 class TwoPaneAdapter( 26 private val dataSet: Array<String>, 27 private val onClick: (CharSequence) -> Unit 28 ) : RecyclerView.Adapter<TwoPaneAdapter.ViewHolder>() { 29 30 class ViewHolder(view: View, val onClick: (CharSequence) -> Unit) : 31 RecyclerView.ViewHolder(view) { 32 val textView: TextView = view.findViewById(R.id.list_pane_row_item) 33 34 init { <lambda>null35 textView.setOnClickListener { onClick(textView.text) } 36 } 37 } 38 onCreateViewHoldernull39 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TwoPaneAdapter.ViewHolder { 40 val view = 41 LayoutInflater.from(parent.context).inflate(R.layout.list_pane_row_item, parent, false) 42 return ViewHolder(view, onClick) 43 } 44 onBindViewHoldernull45 override fun onBindViewHolder(holder: ViewHolder, position: Int) { 46 holder.textView.text = dataSet[position] 47 } 48 getItemCountnull49 override fun getItemCount() = dataSet.size 50 } 51