-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoSuggestAdapterExamples
More file actions
65 lines (60 loc) · 2.39 KB
/
AutoSuggestAdapterExamples
File metadata and controls
65 lines (60 loc) · 2.39 KB
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
55
56
57
58
59
60
61
62
63
//Example 1
//Shows how to use custom class to present non-string adapter options, with data-binding (stripped down to make generic).
//Bound field is an instance of TextInputAutoComlpeteEditText.kt
val merchants : AutoSuggestAdapter<StoreInfoSuggestion> = AutoSuggestAdapter(GEBManager.appContext!!, R.layout.layout_auto_suggest_1line_w_image)
merchants.customLayoutHandler = { view: View, s: StoreInfoSuggestion ->
val v = view as LinearLayout
val img = v.findViewById<ImageView>(R.id.selector_image)
GlideApp.with(context)
.load(image_path)
.override(128,128)
.fitCenter()
.into(img)
val txt = v.findViewById<TextView>(R.id.selector_text)
txt.text = s.merchant
}
val mList : MutableList<StoreInfoSuggestion> =
if(no_data_avail) ArrayList()
else {
val h = avail_data as HashMap<Any,Any>
val m = ArrayList<StoreInfoSuggestion>()
h.forEach { (key, value) -> m.add(StoreInfoSuggestion(value1, value2)) }
m
}
merchants.addAll(mList)
binding.boundField.threshold = 1
binding.boundField.setAdapter(merchants)
binding.boundField.onItemClickListener = object : AdapterView.OnItemClickListener {
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val sis = parent?.getItemAtPosition(position) as StoreInfoSuggestion
//Code to run when item selected if needed
}
}
internal class StoreInfoSuggestion(val value1 : String, val value2 : String) {
override fun toString(): String = value1
}
//Layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp" >
<ImageView
android:id="@+id/selector_image"
android:layout_width="0dp"
android:layout_height="32dp"
android:adjustViewBounds="true"
android:layout_weight="1" />
<TextView
android:id="@+id/selector_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_weight="4"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dp"
android:text="Sample" />
</LinearLayout>