1 package com.xtremelabs.robolectric.shadows;
2 
3 import com.xtremelabs.robolectric.internal.Implementation;
4 import com.xtremelabs.robolectric.internal.Implements;
5 
6 import android.widget.AdapterView;
7 import android.widget.AdapterView.OnItemClickListener;
8 import android.widget.AutoCompleteTextView;
9 import android.widget.Filterable;
10 import android.widget.ListAdapter;
11 
12 /**
13  * A shadow for AutoCompleteTextView
14  */
15 @Implements(AutoCompleteTextView.class)
16 public class ShadowAutoCompleteTextView extends ShadowEditText {
17 
18     private ListAdapter adapter;
19     private int threshold = 2;
20     private OnItemClickListener onItemClickListener;
21 
22     @Implementation
getAdapter()23     public ListAdapter getAdapter() {
24         return adapter;
25     }
26 
27     @Implementation
setAdapter(T adapter)28     public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
29         this.adapter = adapter;
30     }
31 
32     @Implementation
getThreshold()33     public int getThreshold() {
34         return threshold;
35     }
36 
37     @Implementation
setThreshold(int threshold)38     public void setThreshold(int threshold) {
39         if (threshold <= 0) {
40             threshold = 1;
41         }
42         this.threshold = threshold;
43     }
44 
45     @Implementation
getOnItemClickListener()46     public AdapterView.OnItemClickListener getOnItemClickListener() {
47         return onItemClickListener;
48     }
49 
50     @Implementation
setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener)51     public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
52         this.onItemClickListener = onItemClickListener;
53     }
54 
55     @Implementation
replaceText(CharSequence text)56     public void replaceText(CharSequence text) {
57         setText(text);
58         setSelection(getText().length());
59     }
60 }
61