skydoves / PowerSpinner

🌀 A lightweight dropdown popup spinner, fully customizable with an arrow and animations for Android.
Apache License 2.0
1.21k stars 116 forks source link

item layout order #28

Closed Meglali20 closed 4 years ago

Meglali20 commented 4 years ago

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

skydoves commented 4 years ago

Hi @Meglali20, You can create a custom adapter using your own customized layout style. The IconSpinnerAdapter is one of the customized adapters provided in this library.

Meglali20 commented 4 years ago

Hi @Meglali20, You can create a custom adapter using your own customized layout style. The IconSpinnerAdapter is one of the customized adapters provided in this library.

Thank you for your answer. I am using java, I added a custom adapter the problem is with this override fun notifyItemSelected(index: Int) { this.spinnerView.notifyItemSelected(index, this.spinnerItems[index].text) this.onSpinnerItemSelectedListener?.onItemSelected(index, this.spinnerItems[index]) }

@NotNull
@Override
public PowerSpinnerView getSpinnerView() {
    return null;
}

it returns a null and must be NonNull where should I assign the PowerSpinnerView it should return?

skydoves commented 4 years ago

As you can see the IconSpinnerAdapter, You can hand over PwerSpinnerView via the constructor. Also when implementing your custom adapter, you should define PowerSpinnerView field in your class and it can be used for applying attributes on your own ViewHolder. The PowerSpinnerView has many kinds of attributes including text color, typeface, text size, padding or etc from XML layout. And they might be used in your custom adapter.

Meglali20 commented 4 years ago

@skydoves but where to assign the value of powerSpinnerView?

skydoves commented 4 years ago

For writing an example of the IconSpinnerAdapter:

IconSpinnerAdapter adapter = new IconSpinnerAdapter(myPowerSpinnerView);

Add a new constructor to your custom adapter.

skydoves commented 4 years ago

Here is an example codes using IconSpinnerItem written Java.

class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomViewHolder>
  implements PowerSpinnerInterface<IconSpinnerItem> {

  private PowerSpinnerView powerSpinnerView;

  public CustomAdapter(PowerSpinnerView powerSpinnerView) {
    this.powerSpinnerView = powerSpinnerView;
  }

  @NotNull @Override public PowerSpinnerView getSpinnerView() {
    return powerSpinnerView;
  }
Meglali20 commented 4 years ago

Thank you, I got this part, but when calling notifyItemSelected(i, String.valueOf(i)); it will only set the text for the powerSpinnerView not display the image or the full item

Meglali20 commented 4 years ago

@skydoves
I figured it out from the IconSpinnerAdapter.kt class, thank you for your help!