spinner - Android Custom Multispinner: Implement FadingEdge scroll -
i android newbie , have used code here: https://stackoverflow.com/a/17577310/6412402 create custom multispinner (it works great!) graphic designer friend hates me/the current layout , wants ios-like scroll options user has passed fade view (similar how scrollview has fadingedge length) how give custom spinner fading edge length similar this: fading scroll
except fading scroll image text , want items in custom spinner have property. doesn't have picture need kind of fading property. please help! here code in java class multispinner:
package packagename; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.content.dialoginterface.onmultichoiceclicklistener; import android.content.res.typedarray; import android.util.attributeset; import android.widget.arrayadapter; import android.widget.spinner; import java.util.list; public class multispinner extends spinner { private charsequence[] entries; private boolean[] selected; private multispinnerlistener listener; public multispinner(context context, attributeset attrs) { super(context, attrs); typedarray = context.obtainstyledattributes(attrs, r.styleable.multispinner); entries = a.gettextarray(r.styleable.multispinner_android_entries); if (entries != null) { selected = new boolean[entries.length]; // false-filled default } a.recycle(); } private onmultichoiceclicklistener monmultichoiceclicklistener = new onmultichoiceclicklistener() { @override public void onclick(dialoginterface dialog, int which, boolean ischecked) { selected[which] = ischecked; } }; private dialoginterface.onclicklistener monclicklistener = new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // build new spinner text & delimiter management stringbuffer spinnerbuffer = new stringbuffer(); (int = 0; < entries.length; i++) { if (selected[i]) { spinnerbuffer.append(entries[i]); spinnerbuffer.append(", "); } } // remove trailing comma if (spinnerbuffer.length() > 2) { spinnerbuffer.setlength(spinnerbuffer.length() - 2); } // display new text arrayadapter<string> adapter = new arrayadapter<string>(getcontext(), android.r.layout.simple_spinner_item, new string[] { spinnerbuffer.tostring() }); setadapter(adapter); if (listener != null) { listener.onitemsselected(selected); } // hide dialog dialog.dismiss(); } }; @override public boolean performclick() { new alertdialog.builder(getcontext()) .setmultichoiceitems(entries, selected, monmultichoiceclicklistener) .setpositivebutton(android.r.string.ok, monclicklistener) .show(); return true; } public void setmultispinnerlistener(multispinnerlistener listener) { this.listener = listener; } public interface multispinnerlistener { public void onitemsselected(boolean[] selected); } }
and xml code
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.nestedscrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fadingedgelength="400dp" android:requiresfadingedge="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="edu.ucsb.cs.cs185.project.cookey.scrollingactivity" tools:showin="@layout/activity_scrolling"> <packagename.multispinner android:id="@+id/multispinner" android:layout_width="match_parent" android:layout_height="match_parent" android:entries="@array/multispinner_entries" android:fadingedgelength="300dp" android:requiresfadingedge="vertical"/> </android.support.v4.widget.nestedscrollview>