AutofillListAdapter.java revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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
6package org.chromium.ui.autofill;
7
8import android.content.Context;
9import android.text.TextUtils;
10
11import android.view.LayoutInflater;
12import android.view.View;
13import android.view.ViewGroup;
14import android.widget.ArrayAdapter;
15import android.widget.TextView;
16
17import org.chromium.ui.R;
18
19import java.util.ArrayList;
20
21/**
22 * Autofill suggestion adapter for AutofillWindow.
23 */
24public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> {
25    private Context mContext;
26
27    AutofillListAdapter(Context context, ArrayList<AutofillSuggestion> objects) {
28        super(context, R.layout.autofill_text, objects);
29        mContext = context;
30    }
31
32    @Override
33    public View getView(int position, View convertView, ViewGroup parent) {
34        View layout = convertView;
35        if (convertView == null) {
36            LayoutInflater inflater =
37                    (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
38            layout = inflater.inflate(R.layout.autofill_text, null);
39        }
40        TextView labelView = (TextView) layout.findViewById(R.id.autofill_label);
41        labelView.setText(getItem(position).mLabel);
42
43        TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sublabel);
44        CharSequence sublabel = getItem(position).mSublabel;
45        if (TextUtils.isEmpty(sublabel)) {
46            sublabelView.setVisibility(View.GONE);
47        } else {
48            sublabelView.setText(sublabel);
49            sublabelView.setVisibility(View.VISIBLE);
50        }
51
52        return layout;
53    }
54}
55