Giter VIP home page Giter VIP logo

powerspinner's Introduction

PowerSpinner


🌀 A lightweight dropdown popup spinner, fully customizable with an arrow and animations for Android.


License API Build Status Android Weekly Medium Profile Javadoc


Including in your project

Maven Central

Gradle

Add the dependency below to your module's build.gradle file:

dependencies {
    implementation "com.github.skydoves:powerspinner:1.2.7"
}

SNAPSHOT

PowerSpinner
Snapshots of the current development version of PowerSpinner are available, which track the latest versions.

repositories {
   maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

Usage

Add the XML namespace below inside your XML layout file:

xmlns:app="http://schemas.android.com/apk/res-auto"

PowerSpinnerView in XML

You can implement PowerSpinnerView in your XML layout as the below example. You can use PowerSpinnerView same as TextView. For instance, you can set the default text with the hint and textColorHint attributes..

<com.skydoves.powerspinner.PowerSpinnerView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@color/md_blue_200"
  android:gravity="center"
  android:hint="Question 1"
  android:padding="10dp"
  android:textColor="@color/white_93"
  android:textColorHint="@color/white_70"
  android:textSize="14.5sp"
  app:spinner_arrow_gravity="end"
  app:spinner_arrow_padding="8dp"
  app:spinner_divider_color="@color/white_70"
  app:spinner_divider_show="true"
  app:spinner_divider_size="0.4dp"
  app:spinner_item_array="@array/questions"
  app:spinner_item_height="46dp"
  app:spinner_popup_animation="dropdown"
  app:spinner_popup_background="@color/background800"
  app:spinner_popup_elevation="14dp" />

Create PowerSpinner with Kotlin extension

You can also create the PowerSpinnerView programmatically with the Kotlin extension class.

val mySpinnerView = createPowerSpinnerView(this) {
  setSpinnerPopupWidth(300)
  setSpinnerPopupHeight(350)
  setArrowPadding(6)
  setArrowAnimate(true)
  setArrowAnimationDuration(200L)
  setArrowGravity(SpinnerGravity.START)
  setArrowTint(ContextCompat.getColor(this@MainActivity, R.color.md_blue_200))
  setSpinnerPopupAnimation(SpinnerAnimation.BOUNCE)
  setShowDivider(true)
  setDividerColor(Color.WHITE)
  setDividerSize(2)
  setLifecycleOwner(this@MainActivity)
}

Note: It's highly recommended to set the height size of the item with the spinner_item_height attribute or the entire height size of the popup with the spinner_popup_height to implement the correct behaviors of your spinner.

Show and Dismiss

By default, the spinner popup will be displayed when you click the PowerSpinnerView, and it will be dismissed when you select an item. You can also show and dismiss manually with the methods below:

powerSpinnerView.show() // show the spinner popup.
powerSpinnerView.dismiss() // dismiss the spinner popup.

// If the popup is not showing, shows the spinner popup menu.
// If the popup is already showing, dismiss the spinner popup menu.
powerSpinnerView.showOrDismiss()

You can customize the default behaviours of the spinner with the method and property below:

// the spinner popup will not be shown when clicked.
powerSpinnerView.setOnClickListener { }

// the spinner popup will not be dismissed when item selected.
powerSpinnerView.dismissWhenNotifiedItemSelected = false

OnSpinnerItemSelectedListener

You can listen the selection of the spinner items with the setOnSpinnerItemSelectedListener method below:

powerSpinnerView.setOnSpinnerItemSelectedListener<String> { oldIndex, oldItem, newIndex, newText ->
   toast("$text selected!")
}

If you use Java, see the example below:

powerSpinnerView.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<String>() {
  @Override public void onItemSelected(int oldIndex, @Nullable String oldItem, int newIndex, String newItem) {
    toast(item + " selected!");
  }
});

Select an Item by an Index

You can select an item manually/initially with the method below:

powerSpinnerView.selectItemByIndex(4)

Note: selectItemByIndex must be invoked after setting items with the setItems method.

Store and Restore a selected Position

You can store and restore the selected position automatically and it will be re-selected automatically when the PowerSpinnerView is inflated with the property below:

powerSpinnerView.preferenceName = "country"

You can also set the property above with the attribute below in your XML layout:

app:spinner_preference_name="country"

You can remove or clear the stored position data with the methods below:

powerSpinnerView.clearSelectedItem()

SpinnerAnimation

You can set an animation when you display and dismiss the spinner with the method below:

app:spinner_popup_animation="normal"

This library supports the four animations below:

SpinnerAnimation.NORMAL
SpinnerAnimation.DROPDOWN
SpinnerAnimation.FADE
SpinnerAnimation.BOUNCE
NORMAL DROPDOWN FADE BOUNCE

IconSpinnerAdapter

You can also check out the dafult custom adapter, IconSpinnerAdapter with the setItems and IconSpinnerItem methods below:

spinnerView.apply {
  setSpinnerAdapter(IconSpinnerAdapter(this))
  setItems(
    arrayListOf(
        IconSpinnerItem(text = "Item1", iconRes = R.drawable.unitedstates),
        IconSpinnerItem(text = "Item2", iconRes = R.drawable.southkorea)))
  getSpinnerRecyclerView().layoutManager = GridLayoutManager(context, 2)
  selectItemByIndex(0) // select a default item.
  lifecycleOwner = this@MainActivity
}

Note: You can get the RecyclerView of the spinner with the getSpinnerRecyclerView() method.

If you use Java, see the example below:

List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
iconSpinnerItems.add(new IconSpinnerItem("item1", contextDrawable(R.drawable.unitedstates)));

IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(spinnerView);
spinnerView.setSpinnerAdapter(iconSpinnerAdapter);
spinnerView.setItems(iconSpinnerItems);
spinnerView.selectItemByIndex(0);
spinnerView.setLifecycleOwner(this);

Custom Spinner Adapter

You can also implement your own custom adapter and bind to the PowerSpinnerView. Firstly, create a new adapter and viewHolder, which extend each RecyclerView.Adapter and PowerSpinnerInterface<T> below:

class MySpinnerAdapter(
  powerSpinnerView: PowerSpinnerView
) : RecyclerView.Adapter<MySpinnerAdapter.MySpinnerViewHolder>(),
  PowerSpinnerInterface<MySpinnerItem> {

  override var index: Int = powerSpinnerView.selectedIndex
  override val spinnerView: PowerSpinnerView = powerSpinnerView
  override var onSpinnerItemSelectedListener: OnSpinnerItemSelectedListener<MySpinnerItem>? = null

With the custom spinner adapter, you can use your own custom spinner item, which includes information of the spinner item.

Note: You shoud override the spinnerView, onSpinnerItemSelectedListener properties and setItems, notifyItemSelected methods.

Next, you must call spinnerView.notifyItemSelected method when your item is clicked or the spinner item should be changed:

override fun onBindViewHolder(holder: MySpinnerViewHolder, position: Int) {
  holder.itemView.setOnClickListener {
    notifyItemSelected(position)
  }
}

// You must call the `spinnerView.notifyItemSelected` method to let `PowerSpinnerView` know the item is changed.
override fun notifyItemSelected(index: Int) {
  if (index == NO_SELECTED_INDEX) return
  val oldIndex = this.index
  this.index = index
  this.spinnerView.notifyItemSelected(index, this.spinnerItems[index].text)
  this.onSpinnerItemSelectedListener?.onItemSelected(
      oldIndex = oldIndex,
      oldItem = oldIndex.takeIf { it != NO_SELECTED_INDEX }?.let { spinnerItems[oldIndex] },
      newIndex = index,
      newItem = item
    )
}

Lastly, you can add the item selected listener like the below:

spinnerView.setOnSpinnerItemSelectedListener<MySpinnerItem> { 
  oldIndex, oldItem, newIndex, newItem -> toast(newItem.text) 
}

Custom Scrollbar

You can customize attributes of the scrollbar by defining your own style in your styles.xml file like the below:

<style name="PowerSpinnerStyle">
  <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
  <item name="android:scrollbars">vertical</item>
  <item name="android:fadeScrollbars">false</item>
  <item name="android:scrollbarSize">2dp</item>
  <item name="android:scrollbarThumbVertical">@drawable/powerspinner_scrollbar</item>
</style>

You can also customize the drawable of the scrollbar by creating powerspinner_scrollbar.xml file like the below:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@color/colorPrimaryDark" />
  <corners android:radius="6dp" />
</shape>

Then the library will use the overwritten customized styles.

Note: Please keep in mind you should use the exactly same name for PowerSpinnerStyle and powerspinner_scrollbar.xml to apply your custom styles.

PowerSpinnerPreference

You can use PowerSpinnerView in your PreferenceScreen XML for building preferences screens. Add the dependency below to your module's build.gradle file:

dependencies {
    implementation "androidx.preference:preference-ktx:1.2.0"
}

You can implement the spinner preference with the PowerSpinnerPreference in your XML file below:

<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <androidx.preference.Preference
    android:title="Account preferences"
    app:iconSpaceReserved="false" />

  <com.skydoves.powerspinner.PowerSpinnerPreference
    android:key="question1"
    android:title="Question1"
    app:spinner_arrow_gravity="end"
    app:spinner_arrow_padding="8dp"
    app:spinner_divider_color="@color/white_70"
    app:spinner_divider_show="true"
    app:spinner_divider_size="0.2dp"
    app:spinner_item_array="@array/questions1"
    app:spinner_popup_animation="dropdown"
    app:spinner_popup_background="@color/background900"
    app:spinner_popup_elevation="14dp" />

You don't need to set preferenceName attribute, and OnSpinnerItemSelectedListener should be set on PowerSpinnerPreference. You can reference this sample codes.

val countySpinnerPreference = findPreference<PowerSpinnerPreference>("country")
countySpinnerPreference?.setOnSpinnerItemSelectedListener<IconSpinnerItem> { oldIndex, oldItem, newIndex, newItem ->
  Toast.makeText(requireContext(), newItem.text, Toast.LENGTH_SHORT).show()
}

Avoid Memory Leak

Dialog, PopupWindow and etc.. have memory leak issue if not dismissed before activity or fragment are destroyed. But Lifecycles are now integrated with the Support Library since Architecture Components 1.0 Stable released. So you can solve the memory leak issue simply by setting the lifecycle owner with the method below:

.setLifecycleOwner(lifecycleOwner)

By setting the lifecycle owner, the dismiss() method will be invoked automatically before destroying your activity or fragment.

PowerSpinnerView Attributes

Attributes Type Default Description
spinner_arrow_drawable Drawable arrow arrow drawable.
spinner_arrow_show Boolean true sets the visibility of the arrow.
spinner_arrow_gravity SpinnerGravity end the gravity of the arrow.
spinner_arrow_padding Dimension 2dp padding of the arrow.
spinner_arrow_tint Color None tint color of the arrow.
spinner_arrow_animate Boolean true show arrow rotation animation when showing.
spinner_arrow_animate_duration Integer 250 the duration of the arrow animation.
spinner_divider_show Boolean true show the divider of the popup items.
spinner_divider_size Dimension 0.5dp sets the height of the divider.
spinner_divider_color Color White sets the color of the divider.
spinner_popup_width Dimension spinnerView's width the width of the popup.
spinner_popup_height Dimension WRAP_CONTENT the height of the popup.
spinner_item_height Dimension WRAP_CONTENT a fixed item height of the popup.
spinner_popup_background Color spinnerView's background the background color of the popup.
spinner_popup_animation SpinnerAnimation NORMAL the spinner animation when showing.
spinner_popup_animation_style Style Resource -1 sets the customized animation style.
spinner_popup_elevation Dimension 4dp the elevation size of the popup.
spinner_item_array String Array Resource null sets the items of the popup.
spinner_dismiss_notified_select Boolean true sets dismiss when the popup item is selected.
spinner_debounce_duration Integer 150 A duration of the debounce for showOrDismiss.
spinner_preference_name String null saves and restores automatically the selected position.

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐
And follow me for my next creations! 🤩

License

Copyright 2019 skydoves (Jaewoong Eum)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the L

powerspinner's People

Contributors

gerasimosgots avatar lifeparticle avatar recsater avatar renezuidhof avatar skydoves avatar wxw-9527 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powerspinner's Issues

powerSpinner.setSelection()

Please complete the following information:

  • Library Version 1.0.5
  • Affected Device(s) A51 Android 10

I can't find the function setSelection to initialize the spinner to its default status as nothing was selected yet.
Thank you in advance

Width is 0

Please complete the following information:

  • Library Version : 1.0.9
  • Affected Device(s) : Google Pixel

Describe the Bug:

The dropdown menu isn't showing on click of the powerspinner. On debugging I found out the width of the view is 0. If I use spinner_popup_width with some value the dropdown shows.

Expected Behavior:
The dropdown should show

Doesn't Work

<com.skydoves.powerspinner.PowerSpinnerView
                       android:id="@+id/powerspinner"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                       android:layout_marginHorizontal="@dimen/space.medium"
                       android:layout_marginTop="@dimen/space.small"
                       android:background="@drawable/text_display_border"
                       android:backgroundTint="#2E5BFF"
                       android:gravity="start"
                       android:hint="@string/hint"
                       android:padding="@dimen/space.medium"
                       android:textColor="#57779e"
                       app:spinner_arrow_drawable="@drawable/ic_dropdown"
                       app:spinner_divider_color="#80A5A1DC"
                       app:spinner_divider_show="true"
                       app:spinner_popup_animation="dropdown"
                       app:spinner_popup_background="@color/white" />

Works


 <com.skydoves.powerspinner.PowerSpinnerView
                        android:id="@+id/powerspinner"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginHorizontal="@dimen/space.medium"
                        android:layout_marginTop="@dimen/space.small"
                        android:background="@drawable/text_display_border"
                        android:backgroundTint="#2E5BFF"
                        android:gravity="start"
                        android:hint="@string/select_asset_id"
                        android:padding="@dimen/space.medium"
                        android:textColor="#57779e"
                        app:spinner_arrow_drawable="@drawable/ic_dropdown"
                        app:spinner_divider_color="#80A5A1DC"
                        app:spinner_divider_show="true"
                        app:spinner_popup_animation="dropdown"
                        app:spinner_popup_background="@color/white"
                        app:spinner_popup_width="100dp" />

unable to disable OverScrollMode

Please complete the following information:

  • Library Version [e.g. v1.0.9]
  • Affected Device(s) [ Asus Zenphone , android 9]

Describe the Bug:
i'm using custom adapter
class my_adapter extends RecyclerView.Adapter implements PowerSpinnerInterface

i tried setting powerSpinnersetOverScrollMode(View.OVER_SCROLL_NEVER)
still i see the overScroll effect at top and bottom of list

Expected Behavior:
OverScroll effect should be hidden

Dropdown items height change 2nd time

Please complete the following information:

  • Library Version [e.g. v1.0.6]
  • Affected Device(s) [e.g. Realme x2 with Android 10.0]

Items height change when again click on the spinner


Items height change should remain the same

Potentially more Question than Bug - Item Layout issues

Please complete the following information:

  • 1.1.0
  • Google Pixel Android 8

Describe the Bug:

Potentially more of a question than a bug, but the selectedItem text is offset and is not centered.
I was also wondering how to increase the height of each Item, and also how to adjust the padding of each item?

Screenshot_1598650799

Expected Behavior:

I would have thought the text in for the selected item would be centered in the view

Popup is not visible when the PowerSpinner is located at the bottom of a layout

Please complete the following information:

  • Library Version [v1.1.5]
  • Affected Device(s) [Google Pixel 3a]

Describe the Bug:

If the PowerSpinner is at the bottom of a layout, the popup is not visible. Or if it is near the bottom of a layout only one or two entries are visible.

Expected Behavior:

The popup should be shown above the PowerSpinner if the view is located in the bottom half of the layout.

setOnSpinnerOutsideTouchListener does not fire

Please complete the following information:

  • Library Version [e.g. v1.0.0] : 1.0.5
  • Affected Device(s) : Google Pixel 3a

Describe the Bug:

Im using Kotlin with PowerSpinner, setting the onSpinnerOutsideTouchListener using setOnSpinnerOutsideTouchListener { view, motionEvent -> } does not get fired while touching outside spinner when the spinner is open

Expected Behavior:

Expect to get event fired when touching outside spinner when the spinner is open, so that I could close the spinner. It would be good if the spinner could be closed when user click the physical back button.

NOT CLOSED WHEN CLICKED ANOTHER VIEW

Please complete the following information:

  • Library Version [e.g. v1.1.7]

Popup not closed automatically when you click another layout in the screen. you have to click an item to close popup

I think that It must be closed automatically.

On Scrolling down . The listing order changes

  • Library Version [1.0.8]
  • Affected Device(s) Realme X2 Pro with Android 10]

I have a list of objects in which each object indicate Year
Its like 1970 - 2020
I have created custom adapter.
On clicking the spinner, the list is displayed from 1970 to 1980
On scrolling down, the year displaying is random

getting null error on passing object list to spinner

error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.gueyedeapp, PID: 13713
    java.lang.ClassCastException: c.c.a.g.e.a.a$a cannot be cast to java.lang.CharSequence
        at c.g.a.b.z(:43)
        at c.g.a.b.m(:26)
        at androidx.recyclerview.widget.RecyclerView$g.n(:7065)
        at androidx.recyclerview.widget.RecyclerView$g.d(:7107)
        at androidx.recyclerview.widget.RecyclerView$u.F(:6012)
        at androidx.recyclerview.widget.RecyclerView$u.G(:6279)
        at androidx.recyclerview.widget.RecyclerView$u.p(:6118)
        at androidx.recyclerview.widget.RecyclerView$u.o(:6114)
        at androidx.recyclerview.widget.LinearLayoutManager$c.d(:2303)
        at androidx.recyclerview.widget.LinearLayoutManager.r2(:1627)
        at androidx.recyclerview.widget.LinearLayoutManager.U1(:1587)
        at androidx.recyclerview.widget.LinearLayoutManager.X0(:665)
        at androidx.recyclerview.widget.RecyclerView.D(:4134)
        at androidx.recyclerview.widget.RecyclerView.onMeasure(:3540)
        at android.view.View.measure(View.java:17765)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5620)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:454)
        at android.view.View.measure(View.java:17765)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2349)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1373)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1597)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1251)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6438)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:795)
        at android.view.Choreographer.doCallbacks(Choreographer.java:598)
        at android.view.Choreographer.doFrame(Choreographer.java:567)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:781)
        at android.os.Handler.handleCallback(Handler.java:810)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:189)
        at android.app.ActivityThread.main(ActivityThread.java:5532)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)

this what i done so far

xml

<com.skydoves.powerspinner.PowerSpinnerView
                    android:id="@+id/spinnerCategory"
                    style="@style/fontRegular"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:layout_marginStart="@dimen/_10sdp"
                    android:layout_marginTop="@dimen/_20sdp"
                    android:layout_marginEnd="@dimen/_10sdp"
                    android:background="@drawable/background_button_white_20dp"
                    android:drawableEnd="@drawable/ic_search_gray"
                    android:drawablePadding="@dimen/_7sdp"
                    android:elevation="1dp"
                    android:hint="@string/category"
                    android:padding="@dimen/_9sdp"
                    android:textColor="@color/black"
                    android:textSize="@dimen/_12ssp"
                    app:spinner_arrow_gravity="end"
                    app:spinner_arrow_padding="8dp"
                    app:spinner_divider_color="@color/black"
                    app:spinner_divider_show="true"
                    app:spinner_divider_size="0.4dp"
                    app:spinner_popup_animation="dropdown"
                    app:spinner_popup_elevation="14dp" />

java

override fun setCategoryList(response: CategoryListModel) {
        activity?.hideKeybord()
        hideProgressBar()
        mList.clear()
        mList.addAll(response.data)
        binding.spinnerCategory.apply {
            setItems(mList)
            setOnSpinnerItemSelectedListener<CategoryListModel.CategoryListData> { _, item ->
                binding.spinnerCategory.hint = item.categoryName
                Toast.makeText(context, item.categoryName, Toast.LENGTH_SHORT).show()
            }
            lifecycleOwner = this@SearchFragment
            preferenceName = getString(R.string.category)
        }
}

I am setting spinner when I get a response from API

this is my model class


import com.google.gson.annotations.SerializedName

data class CategoryListModel(
    @SerializedName("data")
    val `data`: List<CategoryListData> = listOf(),
    @SerializedName("FLAG")
    val fLAG: Boolean = false,
    @SerializedName("IS_ACTIVE")
    val iSACTIVE: Int = 0,
    @SerializedName("MESSAGE")
    val mESSAGE: String = ""
) {
    data class CategoryListData(
        @SerializedName("category_name")
        val categoryName: String = "",
        @SerializedName("created_by")
        val createdBy: String = "",
        @SerializedName("created_date")
        val createdDate: String = "",
        @SerializedName("id")
        val id: String = "",
        @SerializedName("modified_by")
        val modifiedBy: String = "",
        @SerializedName("modified_date")
        val modifiedDate: String = "",
        @SerializedName("status")
        val status: String = ""
    )
}

please suggest me why I am getting an error

Multi Select Item With Input Value

Hi,

Can you please add a feature and provide sample code of a multi select item spinner with having quantity input field?

Like user can select different items and provide different quantities of selected items.

- Library version is 1.1.5.

Please complete the following information:

  • Library Version [e.g. v1.0.0]
  • Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0]

Describe the Bug:

Add a clear description about the problem.

Expected Behavior:

A clear description of what you expected to happen.

App Crash on when using the spinner Android 6 and below

Please complete the following information:

  • Library Version V1.1.3
  • Affected Device(s) Android 6 and below

Describe the Bug:

Hello,
There's a bug that is being reported by crashlytics on Android 5 and 6 and I faced when testing on Android 4.4 that causes the app to crash when using the spinner.
it's working fine on Android 10 and Android 8
this the logcat

    java.lang.NullPointerException
        at android.widget.PopupWindow.update(PopupWindow.java:1375)
        at com.skydoves.powerspinner.PowerSpinnerView$updateSpinnerWindowSize$1.run(PowerSpinnerView.kt:496)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)


Is there any fix for this problem as I am getting multiple crashes on Android 5 and 6.
Thanks.

popup dismiss

  • Library Version [1.1.6]
  • Affected Device(s) [e.g. Vivo V15pro with Android 10]

Description of the Bug:
When adding two or more powerspinner,.
we select spinner first it shows popup window and then we select spinner second it shows popup window without dismissing the previous popup window.

Expected Behavior:

It should dismiss previous opened popup window and then show the newly selected or clicked spinner.

Access to `binding.body`

Is your feature request related to a problem?

I have the list inside the item of the spinnerRecyclerView. I want to recalculate body height when a list is visible.

Describe the solution you'd like:

Additinonal public method:

fun getSpinnerBody(): RecyclerView = binding.body

Vertical scroll bar doesn't appear.

  • Library Version: 1.0.8 (latest)
  • Affected Device: Doesn't work on any device

I am trying to add vertical scrollbar to the dropdown but it doesn't appear. I tried applying vertical scrollbar in xml as well as in Java.
I am restricting the dropdown height so that the scrollbar appears but it doesn't work


android:maxHeight="100dp"  
android:fadeScrollbars="false"
android:scrollbarFadeDuration="0" 
android:verticalScrollbarPosition="right" 
android:scrollbarThumbVertical="@android:color/black"
android:scrollbarAlwaysDrawVerticalTrack="true" 
android:scrollbarSize="20dp" 
android:scrollbarStyle="outsideInset" 
android:scrollbars="vertical"


I also tried changing this in java but scrollbar doesn't work. 
Please help me solve this. Thanks

Feature to support difference between the spinner and the popup.

Is your feature request related to a problem?

A clear and concise description of what the problem is.

Describe the solution you'd like:

A clear and concise description of what you want to happen.

Describe alternatives you've considered:

A clear description of any alternative solutions you've considered.

Feature to support difference between spinner and popup

Is your feature request related to a problem?
Yes.

A clear and concise description of what the problem is.
Basically I need to set a border color only to the spinner. So after adding the border background, the popup is so close that it hides the bottom border.

Describe the solution you'd like:
Feature to support difference between spinner and popup

A clear and concise description of what you want to happen.
An attribute that supports this difference.

Describe alternatives you've considered:
Tried appending PowerSpinner xml to Relative layout ad setting background of the relative layout only. Same problem.

A clear description of any alternative solutions you've considered.
<RelativeLayout
lh..
lw..
background="@drawable/border"
..>
<PowerSpinner
..
/>

pop item wrap width

how can i user wrap_content to pop item width?
when i dynamic set spinner items

thank you

Example for custom adapter

Hi, would you kindly provide example for custom adapter. Currently I manage to implement using custom adapter. Everything work except the on click listener not working. Thanks

Vertical scroll bar color changing

Is your feature request related to a problem? Yes

I have added a vertical scroll bar to dropdown using this new release . I know the fact that Recycler view has it's limitation.

Is there any other way to add the dropdown vertical bar color? Please help.

Intermittent failure to resize the dropdown view after calling spinner.setItems(choices);

Please complete the following information:

  • Library Version v1.1.0 and maybe 1.0.9
  • Affected Device(s) emulator and devices

Describe the Bug:
This is an intermittent bug. I didn't see it for a whole day and then today it started happening. I built the simplest test case. The simple test case failed for about an hour, then I changed some parameters to show the scroll case (count = 3 and pos = 2) and it stopped failing. I set it back and it wasn't failing. I switched between library 1.0.9 and 1.1.0 and the bug returned.

    spinner.setDismissWhenNotifiedItemSelected(false);

When spinner.setItems is called with a different number of items, (by pressing the one, two, three choices) the popup list sometimes does not change in size. If the list grows, you have to scroll to see the rest. If the list shrinks, there is a blank space after the last item. Fortunately, I have screen shots of both cases.

Steps to reproduce:

  1. Run the attached app in simulator. Defaults to 5 choices.
  2. Select one should shrink to two choices without extra white space below.
    If it fails it will never fix itself during the same app run. If it succeeds it wont'f fail during the same app run.

Expected Behavior:

The list should always dynamically change. I sent you a video yesterday when it was behaving correctly. Attaching project files and screenshots.

MyApplication4.zip
Screen Shot 2020-07-20 at 7 32 35 PM
Screen Shot 2020-07-20 at 5 58 07 PM
Screen Shot 2020-07-20 at 7 30 57 PM

Error setOnSpinnerItemSelectedListener

  • Library Version [1.0.4]
  • Affected Device(s) [A51 Android 10]

Describe the Bug:
Here is my code in java:
countrySpinner.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
@OverRide public void onItemSelected(int position, String item) {
switch (countrySpinner.getSelectedIndex()){
case 1: visaTypeSpinner.setItems(R.array.Cuba);
case 2: visaTypeSpinner.setItems(R.array.Dubai);
default:;
}
}
});

Here is the error i get when i compile
error: cannot access Function2
countrySpinner.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
^
class file for kotlin.jvm.functions.Function2 not found

PopupWindow out of screen when size is unspecified

Please complete the following information:

  • Library Version v1..0
  • Affected Device(s) emulator and devices

Describe the Bug:

I just put the spinner on the bottom of the screen (with a litle bottom margin), and the popupWindow showed in a small amount of available screen. If I replace the component by the native Spinner, the popup shows correctly, above the control.

I did a quick review of the code, and saw the showAsDropDown method called correctly, but isn't working as expected.

Expected Behavior:

A clear description of what you expected to happen.

Custom adapter using Java

Can you show code for custom adapter using Java, please? Should we Implement PowerSpinnerInterface in the "main activity"? How do we interact between the custom adapter and main activity?

Arrow color is not changeable on Android 6 device

  • Library Version 1.0.9
  • Affected Device(s) [e.g. alps 06 with Android 6.0

Describe the Bug:

android:textColor="@color/colorDarkGreen"
android:background="@color/offWhite" (#eeeeee)
app:spinner_arrow_tint="@color/colorDarkGreen" (#00574B)

Arrow always shows white on older Android version. Even if I change spinner_arrow_tint to #000000

device-2020-07-18-104222

Expected Behavior:

Arrow color should be the same color as the text color, since both are set to the same value.
Arrow color is changeable on simulator and on Samsung A10.

dynamic add powerSpinner in recycleview item

hello

when I use recycle view to dynamic add powerSpinner item row
i found some bug

  1. when i add spinner item and notifyDataSetChanged recycleview
    the spinner popup window will show match cellphone screen width , but my spinner' width not match cellphone screen
    我的每一條row 都有兩個 spinner , 每當我新增並且更新
    點擊spinner 跳出的 popup window 會跟螢幕寬一樣 ,但是我的spinner 只有3分之二 螢幕的寬度而已

  2. when i add Multiple spinner item row in recycleview and notifyItemInserted
    touch some spinner's popup window not show
    當我一次新增多個row 並且新增一次就notifyItemInserted 更新!
    當我點擊比較下面的spinner 之後,他的popup window 並不會show , 但是 arrow 是有在轉的

  3. when i scroll recycle view , the spinner select listener will call and position not current
    當我有多個spinner row 當我滑動recycleview時 spinner的select listener 會觸發
    並且裡面的position 會亂跳! 導致 不會所選的position

thank for all
以上 感謝

if spinner is open and back clicked the spinner remains open and does not destroy

Please complete the following information:

  • Library Version [e.g. v1.0.9]
  • Affected Device(s) [e.g. Pixel 2 with Android 9.0]

Describe the Bug:

if the spinner is open in a fragment and you back click, the spinner remains open and does not destroy this happens when I was using fragments I did not test in activities

Expected Behavior:

close spinner when fragment is poped and closed

error: cannot access Function2

Please complete the following information:

  • Library Version [e.g. v1.0.0]
  • Affected Device(s) [e.g. Samsung Galaxy A01 with Android 10]

Describe the Bug:

On item selected not working

Expected Behavior:

error: cannot access Function2
mBloodSpinner.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener() {
^

The arrow toggle on empty list

Please complete the following information:

  • Library Version [e.g. v1.0.7]
  • Affected Device(s) [Any device]

Describe the Bug:

I've setup the spinner and the data has not been inflated in the spinner till now. So basically its an empty spinner till now. When I click on the spinner it toggles as per the implementation of setOnClickListener() in PowerSpinnerView. I tried to override setOnClickListener() but it did not work. So can you add a check in toggle() that it only toggles if list size > 0.

Something like this : if (adapter.getItems().isNotEmpty()) showOrDismiss()
Need to add a getItems() in adapter classes which will return the list else can add a getSize() too which will return size only.

Expected Behavior:

It should not toggle the list, arrow should not animate.

Get selected Item

Is your feature request related to a problem?

A clear and concise description of what the problem is.

Describe the solution you'd like:

A clear and concise description of what you want to happen.

Describe alternatives you've considered:

A clear description of any alternative solutions you've considered.

setOnSpinnerOutsideTouchListener does not work (Java)

  • Library Version : v 1.0.1

Description:
Java code i wrote to dismiss the spinner when touched outside:
spinnerView.setOnSpinnerOutsideTouchListener((view, motionEvent) -> {
spinnerView.dismiss();
return null;
});
this does not work

Expected Behaviour:
Spinner should dismiss when touched/swiped outside spinner view

setLifecycleOwner

Please complete the following information:

  • Library Version 1.0.3
  • Affected Device(s) [TECNO Camon CX with 7.0, Samsung Galaxy Note 4]

Describe the Bug:
Fatal Exception: java.lang.IllegalArgumentException
The observer class has some methods that use newer APIs which are not available in the current OS version. Lifecycles cannot access even other methods so you should make sure that your observer classes only access framework classes that are available in your min API level OR use lifecycle:compiler annotation processor.

API to get persistent value

Is your feature request related to a problem?

There's no way of accessing a persistent value without looking at the library code and implementing it.

Describe the solution you'd like:

A function to retrieve the value saved at a PowerSpinner by its String ID. Would be cool if it's static so it is not necessary to instance a PowerSpinner.

Describe alternatives you've considered:

Using a PreferenceFragment make the deal but it is difficult to style it (fonts specially).
Getting the SharedPreferences with the name of the package of the library works.

I could make a PR if the feature seems good for you :)

PowerSpinner height when updating the number of children

Describe the Bug:

When updating the recyclerview's children, added children are not showing up.
It appears that the recyclerview can only reduce it's size, therefore if you remove an item then add it back, it won't show up.
This is especially problematic in the case of permission-based buttons using PowerSpinner, where the spinner can be re-used with different entries, each offering different interactions.

Expected Behavior:

When adding or removing a child, let say a button for example, if there is space to show it, it should be shown.

In Java IconSpinnerItem can be created just with 9 parameters

In version 1.1.6 IconSpinnerItem can be created just with 9 parameters.

ArrayList<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
        iconSpinnerItems.add(new IconSpinnerItem("Spain", ContextCompat.getDrawable(getActivity(), R.drawable.spain),null,null,0,null,null,null,null));
        iconSpinnerItems.add(new IconSpinnerItem("US", ContextCompat.getDrawable(getActivity(), R.drawable.unitedstates),null,null,0,null,null,null,null));
        iconSpinnerItems.add(new IconSpinnerItem("UK", ContextCompat.getDrawable(getActivity(), R.drawable.spain),null,null,0,null,null,null,null));

In this implementation Icons are not visible in dropdown!
What should be passed as arguments to constructor so icon will be visible in dropdown?
Thanks for help

item layout order

Hi,
Great spinner! I would like to change something, I want to put the text below the image is there a way to that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.