1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.content.browser.input; 6 7 import android.content.Context; 8 import android.view.LayoutInflater; 9 import android.view.View; 10 import android.view.ViewGroup; 11 import android.widget.ArrayAdapter; 12 import android.widget.TextView; 13 14 import org.chromium.content.R; 15 16 import java.util.List; 17 18 /** 19 * Date/time suggestion adapter for the suggestion dialog. 20 */ 21 class DateTimeSuggestionListAdapter extends ArrayAdapter<DateTimeSuggestion> { 22 private final Context mContext; 23 DateTimeSuggestionListAdapter(Context context, List<DateTimeSuggestion> objects)24 DateTimeSuggestionListAdapter(Context context, List<DateTimeSuggestion> objects) { 25 super(context, R.layout.date_time_suggestion, objects); 26 mContext = context; 27 } 28 29 @Override getView(int position, View convertView, ViewGroup parent)30 public View getView(int position, View convertView, ViewGroup parent) { 31 View layout = convertView; 32 if (convertView == null) { 33 LayoutInflater inflater = LayoutInflater.from(mContext); 34 layout = inflater.inflate(R.layout.date_time_suggestion, parent, false); 35 } 36 TextView labelView = (TextView) layout.findViewById(R.id.date_time_suggestion_value); 37 TextView sublabelView = (TextView) layout.findViewById(R.id.date_time_suggestion_label); 38 39 if (position == getCount() - 1) { 40 labelView.setText(mContext.getText(R.string.date_picker_dialog_other_button_label)); 41 sublabelView.setText(""); 42 } else { 43 labelView.setText(getItem(position).localizedValue()); 44 sublabelView.setText(getItem(position).label()); 45 } 46 47 return layout; 48 } 49 50 @Override getCount()51 public int getCount() { 52 return super.getCount() + 1; 53 } 54 } 55