Skip to content

Commit bddeb0b

Browse files
committed
Add text option adapter
1 parent 40b1d1d commit bddeb0b

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ publish {
3636
userOrg = 'buffer'
3737
groupId = 'org.buffer.android'
3838
artifactId = 'android-components'
39-
publishVersion = '0.18'
39+
publishVersion = '0.19'
4040
desc = 'An Android library for frequently used UI components'
4141
website = 'https://github.com/bufferapp/android-components'
4242
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.buffer.android.components
2+
3+
import android.buffer.org.ui_kit.R
4+
import android.content.Context
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.widget.ArrayAdapter
8+
import android.widget.TextView
9+
10+
open class TextOptionAdapter(
11+
context: Context,
12+
private val values: Array<String>
13+
) : ArrayAdapter<String>(context, R.layout.item_share_option, values) {
14+
15+
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
16+
val optionViewHolder: OptionViewHolder
17+
var shareOptionRow = convertView
18+
if (shareOptionRow == null) {
19+
shareOptionRow = View.inflate(context, R.layout.item_share_option, null)
20+
optionViewHolder = OptionViewHolder(shareOptionRow)
21+
shareOptionRow.tag = optionViewHolder
22+
} else {
23+
optionViewHolder = shareOptionRow.tag as OptionViewHolder
24+
}
25+
optionViewHolder.optionText.text = values[position]
26+
return shareOptionRow!!
27+
}
28+
29+
internal class OptionViewHolder(itemView: View) {
30+
var optionText: TextView = itemView.findViewById<View>(R.id.text_option) as TextView
31+
}
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/text_option"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:layout_gravity="center_vertical"
7+
android:background="?android:attr/selectableItemBackground"
8+
android:padding="16dp"
9+
android:textColor="?android:textColorPrimary"
10+
android:textSize="@dimen/text_body" />

0 commit comments

Comments
 (0)