-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoComplete TextView
46 lines (40 loc) · 1.62 KB
/
AutoComplete TextView
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
//Java Code
public class MainActivity extends AppCompatActivity {
AutoCompleteTextView autoCompleteTextView;
TextView textView;
String details[] = {"Personal Details","Work Details","Graduation Details","Private Details"};
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView = findViewById(R.id.ac_text_view);
textView = findViewById(R.id.textView2);
adapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line,details);
//get suggestion after the number of word types
autoCompleteTextView.setThreshold(1);
//set adapter
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
textView.setText(adapter.getItem(i));
}
});
}
}
//XML Layout
<AutoCompleteTextView
android:id="@+id/ac_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:hint="Search..."
android:padding="12dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="254dp"
android:layout_height="41dp"
android:layout_marginTop="112dp"
android:text="Personal Info."
android:textSize="25sp"/>