1/* 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11package org.webrtc.webrtcdemo; 12 13import android.widget.ArrayAdapter; 14import android.content.Context; 15import android.widget.TextView; 16import android.view.View; 17import android.view.ViewGroup; 18import android.view.LayoutInflater; 19 20public class SpinnerAdapter extends ArrayAdapter<String> { 21 private String[] menuItems; 22 LayoutInflater inflater; 23 int textViewResourceId; 24 25 public SpinnerAdapter(Context context, int textViewResourceId, 26 String[] objects, LayoutInflater inflater) { 27 super(context, textViewResourceId, objects); 28 menuItems = objects; 29 this.inflater = inflater; 30 this.textViewResourceId = textViewResourceId; 31 } 32 33 @Override public View getDropDownView(int position, View convertView, 34 ViewGroup parent) { 35 return getCustomView(position, convertView, parent); 36 } 37 38 @Override public View getView(int position, View convertView, 39 ViewGroup parent) { 40 return getCustomView(position, convertView, parent); 41 } 42 43 private View getCustomView(int position, View v, ViewGroup parent) { 44 View row = inflater.inflate(textViewResourceId, parent, false); 45 TextView label = (TextView) row.findViewById(R.id.spinner_row); 46 label.setText(menuItems[position]); 47 return row; 48 } 49}