Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/AccountsAdapter.java

Issue 628133003: Use View Holder pattern in AccountsAdapter.getView(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.content.Context; 8 import android.content.Context;
9 import android.view.LayoutInflater; 9 import android.view.LayoutInflater;
10 import android.view.View; 10 import android.view.View;
11 import android.view.ViewGroup; 11 import android.view.ViewGroup;
12 import android.widget.ArrayAdapter; 12 import android.widget.ArrayAdapter;
13 import android.widget.TextView; 13 import android.widget.TextView;
14 14
15 /** SpinnerAdapter class used for the ActionBar accounts spinner. */ 15 /** SpinnerAdapter class used for the ActionBar accounts spinner. */
16 public class AccountsAdapter extends ArrayAdapter<Account> { 16 public class AccountsAdapter extends ArrayAdapter<Account> {
17 private LayoutInflater mInflater; 17 private LayoutInflater mInflater;
18 18
19 public AccountsAdapter(Context context, Account[] accounts) { 19 public AccountsAdapter(Context context, Account[] accounts) {
20 // ArrayAdapter only uses the |resource| parameter to return a View from getView() and 20 // ArrayAdapter only uses the |resource| parameter to return a View from getView() and
21 // getDropDownView(). But these methods are overridden here to return cu stom Views, so it's 21 // getDropDownView(). But these methods are overridden here to return cu stom Views, so it's
22 // OK to provide 0 as the resource for the base class. 22 // OK to provide 0 as the resource for the base class.
23 super(context, 0, accounts); 23 super(context, 0, accounts);
24 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INF LATER_SERVICE); 24 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INF LATER_SERVICE);
25 } 25 }
26 26
27 @Override 27 @Override
28 public View getView(int position, View convertView, ViewGroup parent) { 28 public View getView(int position, View convertView, ViewGroup parent) {
29 View view = mInflater.inflate(R.layout.account_selected, parent, false); 29 View view = convertView;
30 if (view == null) {
31 view = mInflater.inflate(R.layout.account_selected, parent, false);
32 }
30 Account account = getItem(position); 33 Account account = getItem(position);
31 TextView target = (TextView) view.findViewById(R.id.account_name); 34 TextView target = (TextView) view.findViewById(R.id.account_name);
32 target.setText(account.name); 35 target.setText(account.name);
33 return view; 36 return view;
34 } 37 }
35 38
36 @Override 39 @Override
37 public View getDropDownView(int position, View convertView, ViewGroup parent ) { 40 public View getDropDownView(int position, View convertView, ViewGroup parent ) {
38 TextView view = (TextView) mInflater.inflate(R.layout.account_dropdown, parent, false); 41 TextView view = (TextView) mInflater.inflate(R.layout.account_dropdown, parent, false);
39 Account account = getItem(position); 42 Account account = getItem(position);
40 view.setText(account.name); 43 view.setText(account.name);
41 return view; 44 return view;
42 } 45 }
43 } 46 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698