2021年4月30日星期五

How Change Color Adapter on List Searchable Spinner Library (KOTLIN)

Haloo everyone, i have problem with change color adapter in searchablespinnerlibrary SearchableSpinner, cannot change color in list spinner.

my xml

 <com.toptoche.searchablespinnerlibrary.SearchableSpinner            android:id="@+id/nama_bangunan"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_below="@+id/nama_bangunan_hint"            android:background="@null"            android:dropDownWidth="match_parent"            android:minHeight="@dimen/spinner_min_height"            android:paddingBottom="4dp" />           

my code

fun getNamaBangunan(KelompokId: Long) {      viewModel.getNamaBangunan(KelompokId)        .observe(viewLifecycleOwner) { bangunanState ->          bangunanState.let { bangunanList ->            when (bangunanList) {              is ResultAsyncState.Completed -> {                if (bangunanList.data.isNotEmpty()) {                  namaBangunanList.clear()                  namaBangunanList.add(JawabanModel(-1, getString(R.string.pilih_di_sini)))                  for (i in bangunanList.data.indices) {                    // LIST WARNA JADI WARNA HIJAU KETIKA DATA SUDAH TERINPUT                    namaBangunanList.add(                      JawabanModel(                        bangunanList.data[i].id!!.toLong(),                        bangunanList.data[i].noUrut!! + " " + "-" + " " + bangunanList.data[i].identifikasi!!                      )                    )                  }                    namaBangunanAdapter = object :                    JawabanArrayAdapter(                      requireContext(),                      R.layout.adapter_answer_option,                      R.id.jawaban_value,                      namaBangunanList                    ) {                    override fun getView(                      position: Int,                      convertView: View?,                      parent: ViewGroup                    ): View {                      val view = super.getView(position, convertView, parent)                      val v = view.findViewById(R.id.jawaban_value) as TextView                      v.setTextColor(Color.parseColor("#008000"))                      return v                    }                      override fun getDropDownView(                      position: Int,                      convertView: View?,                      parent: ViewGroup                    ): View {                      val view =                        super.getDropDownView(position, convertView, parent)                      val tv = view.findViewById(R.id.jawaban_value) as TextView                      if (position === 0) {                        tv.setTextColor(Color.YELLOW)                      } else {                        tv.setTextColor(Color.BLUE)                      }                      return tv                    }                  }                    nama_bangunan.adapter = namaBangunanAdapter                  rumahTangga.bangunanFisikId?.run {                    if (this.isNotBlank()) {                      nama_bangunan.setSelection(namaBangunanAdapter!!.setSelected(this))                    }                  }                } else {                  toast("Data Bangunan Not Found")                }              }              is ResultAsyncState.Failed -> toast(getString(R.string.gagal_mengambil_bangunan_basic))              else -> Timber.e("started to called")            }          }        }    }  

And adapter_answer_option.xml

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:orientation="vertical">      <TextView        android:id="@+id/jawaban_value"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical"        android:lines="2"        android:paddingStart="@dimen/spacing_normal"        android:paddingTop="@dimen/default_nav_item_text_padding"        android:paddingEnd="@dimen/spacing_normal"        android:textAllCaps="true" />  </LinearLayout>  

I want change color in the list adapter, Please help, thank you;

[result_1][1] [1]: https://i.stack.imgur.com/UgkyC.png

[result_2][2] [2]: https://i.stack.imgur.com/Psopl.png

https://stackoverflow.com/questions/67342296/how-change-color-adapter-on-list-searchable-spinner-library-kotlin May 01, 2021 at 10:03AM

没有评论:

发表评论