blob: 0703ab6dcbda9dfe547646ea892a42de7b028c61 (
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
|
// Copyright 2014 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.chromoting;
import android.accounts.Account;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/** SpinnerAdapter class used for the ActionBar accounts spinner. */
public class AccountsAdapter extends ArrayAdapter<Account> {
private LayoutInflater mInflater;
public AccountsAdapter(Context context, Account[] accounts) {
// ArrayAdapter only uses the |resource| parameter to return a View from getView() and
// getDropDownView(). But these methods are overridden here to return custom Views, so it's
// OK to provide 0 as the resource for the base class.
super(context, 0, accounts);
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = mInflater.inflate(R.layout.account_selected, parent, false);
}
Account account = getItem(position);
TextView target = (TextView) view;
target.setText(account.name);
return view;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView view = (TextView) mInflater.inflate(R.layout.account_dropdown, parent, false);
Account account = getItem(position);
view.setText(account.name);
return view;
}
}
|