summaryrefslogtreecommitdiff
path: root/chromium/ui/android/java/src/org/chromium/ui/autofill/AutofillListAdapter.java
blob: 62203dc70a802f4c7268cb3cbbd920f77e4f1956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


package org.chromium.ui.autofill;

import android.content.Context;
import android.text.TextUtils;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import org.chromium.ui.R;

import java.util.ArrayList;

/**
 * Autofill suggestion adapter for AutofillWindow.
 */
public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> {
    private Context mContext;

    AutofillListAdapter(Context context, ArrayList<AutofillSuggestion> objects) {
        super(context, R.layout.autofill_text, objects);
        mContext = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View layout = convertView;
        if (convertView == null) {
            LayoutInflater inflater =
                    (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = inflater.inflate(R.layout.autofill_text, null);
        }
        TextView labelView = (TextView) layout.findViewById(R.id.autofill_label);
        labelView.setText(getItem(position).mLabel);

        TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sublabel);
        CharSequence sublabel = getItem(position).mSublabel;
        if (TextUtils.isEmpty(sublabel)) {
            sublabelView.setVisibility(View.GONE);
        } else {
            sublabelView.setText(sublabel);
            sublabelView.setVisibility(View.VISIBLE);
        }

        return layout;
    }
}