View Implement

Spinner

Papon Ahasan
1 min readDec 13, 2023
<string-array name="feedback_type">
<item>Competitors activities</item>
<item>Customers activities</item>
</string-array>
val feedbackSpinner: Spinner = findViewById(R.id.feedbackSpinner)
val adapter = ArrayAdapter(
this,
R.layout.custom_spinner,
resources.getStringArray(R.array.feedback_type)
)
feedbackSpinner.adapter = adapter

CustomSpinner

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/feedbackSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/feedback_type"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:popupBackground="@color/white" />
class CustomSpinnerAdapter (private val context: Context, private val itemList: List<SpinnerItem>) :
ArrayAdapter<SpinnerItem>(context, R.layout.custom_spinner_item, itemList) {

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = convertView ?: LayoutInflater.from(context)
.inflate( me.ibrahimsn.lib.R.layout.support_simple_spinner_dropdown_item, parent, false)

val textTextView: TextView = view.findViewById(android.R.id.text1)
textTextView.text = getItem(position)?.text ?: ""

return view
}

override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
return getView(position, convertView, parent)
}
}
data class SpinnerItem(val position: Int, val text: String)
val typeList = mutableListOf<SpinnerItem>()
typeList.add(SpinnerItem(it.value, it.name))
val customAdapter = CustomSpinnerAdapter(requireContext(), typeList)
binding.feedbackSpinner.adapter = customAdapter
binding.feedbackSpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
val selectedSpinnerItem = customAdapter.getItem(position)
// Access the selectedSpinnerItem, which contains both position and text
if (selectedSpinnerItem != null) {
feedbackTypeId = selectedSpinnerItem.position
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}

ProgressBar

res > layout > common_loading
-----------------------------
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/progress_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ProgressBar
android:id="@+id/progres"
android:layout_width="40dp"
android:layout_height="40dp"/>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
        
uses in activity or fragmnet
----------
<include
android:id="@+id/progress"
layout="@layout/common_loading"
android:layout_height="match_parent"
android:layout_width="match_parent"/>

Loding Bar

https://github.com/ybq/Android-SpinKit

https://github.com/ibrahimsn98/CirclesLoadingView/blob/master/README.md

ImageSlider

https://gist.github.com/PaponAhasan/a3de7c666926da0f75eb01e25282e9be

--

--