Giter Site home page Giter Site logo

sadra / awesomespinner Goto Github PK

View Code? Open in Web Editor NEW
63.0 3.0 11.0 695 KB

With Awesome Spinner you can implement a material spinner with access to define direction layout and hint text.

Home Page: http://isapanah.com

License: Other

Java 100.00%
android android-library material-design spinner

awesomespinner's Introduction

Awesome Android Spinner

License Dependencies Gitter Minimum Android SDK Version

With Awesome Spinner you can implement a material spinner with access to define direction layout and hint text.

Including the library

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency:

implementation 'com.github.sadra:AwesomeSpinner:1.5.2'

How To Use

Step 1. From very firts, you should add the Awsome Spinner component inside of your layout:

    <com.isapanah.awesomespinner.AwesomeSpinner
        android:id="@+id/my_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
  • If you want to add a default value for hint just add the spinnerHint into your component
  • The default spinner has RTL direction, if you want to declare the direction of spinner just add the spinnerDirection to RTL or LTR so the complete example with LTR direction and hint text to Select a category is:
    <com.isapanah.awesomespinner.AwesomeSpinner
        android:id="@+id/my_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:spinnerDirection="ltr"
        app:spinnerHint="Select a category" />

Step 2. Define the component class into your activity:

AwesomeSpinner my_spinner = (AwesomeSpinner) findViewById(R.id.my_spinner);

Then Create your adapter. For now, there is two way to define apadter:

  • With String List, define a List<String> in your activity and the attach that with your adapter:
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Ariplane");

ArrayAdapter<String> categoriesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);

my_spinner.setAdapter(categoriesAdapter);
  • With String-Array, define a string-array in your strings.xml file and attach that with your adapter:
ArrayAdapter<CharSequence> provincesAdapter = ArrayAdapter.createFromResource(this, R.array.iran_provinces, android.R.layout.simple_spinner_item);

spinnerRTL.setAdapter(provincesAdapter, 0);

Step 3. For final step, you can create a Listener for listening on item selection:

my_spinner.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>() {
    @Override
    public void onItemSelected(int position, String itemAtPosition) {
        //TODO YOUR ACTIONS
    }
});

Additional controls

there is some controls for your spinner:

Control Requierement Info
getSelectedItem() - Result = String: Returns the selected item
getSelectedItemPosition() - Result = int: Returns the selected item position. If there were no selected item, it returns -1.
isSelected() - Result = boolean: Returns true if any item selected, and vice versa.
setSelection(NUMBER) int position You should pass the position of item to select the item programatically.
setSelection(TEXT) String value You should pass the item value to select the item programatically.
setSpinnerHint(TEXT) String value You should pass a sting value as the hint text for the spinner.
setSpinnerEnable(BOOLEAN); Boolean value If you want enable or disable the spinner, you should call this method.
isSpinnerEnable() - Result = boolean: Returns true if the spinner is enabled, and vice versa.
setHintTextColor() int Color If you need to change the Spinner Hint Text color, just call the method and pass you color, ex: Color.BLUE.
setSelectedItemHintColor() int Color If you need to change the Selected Item Hint color, just call the method and pass you color, ex: Color.BLUE.
setDownArrowTintColor() int Color If you need to change the Down Arrow hint color, just call the method and pass you color, ex: Color.BLUE.
setDropDownViewResource(RESOURCE) int Resource If you need to change the Spinner Row stype, just call the method and pass you resource, ex: R.layout.my_sipnner_row_item.
clearSelection() - It clears the spinner selection.

You can see the EXAMPLE PROJECT for more infromation.

License

The MIT License (MIT): https://github.com/amlashi-sadra/AwesomeSpinner/blob/master/LICENSE

Copyright (c) 2017 Sadra Isapanah Amlashi

Website: isapanah.com

Twitter: @sadra_amlashi

awesomespinner's People

Contributors

sadra 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

Watchers

 avatar  avatar  avatar

awesomespinner's Issues

Spinner in scrollview

When spinner in scrollview, after item select, scrollview autoscroll to top.. how to disable it ?

Underline color of spinner

Please provide an attribute to control the color of underline in spinner layout. It's really necessary.

Default Value

How can we set dynamic value to show in hint place ..???

Error while build when supportsRTL is false

Hey, Thanks for this amazing Library, just one thing I disabled the RTL support for the Application, when I wanna build my project and the supportsRTL is false, I can't build a project. is there any solution for this problem?

and this is the log error:

Manifest merger failed : Attribute application@supportsRtl value=(false) from AndroidManifest.xml:21:9-36
is also present at [com.github.amlashi-sadra:AwesomeSpinner:1.0.7] AndroidManifest.xml:14:9-35 value=(true).
Suggestion: add 'tools:replace="android:supportsRtl"' to element at AndroidManifest.xml:15:5-92:19 to override.

How to limit Text in MainView inside spinner

Once Again sir i have small issue to limit text inside spinner i have implemented but the text is to lengthy so i wanted to limit the text At least 20Letter so it look better. Thank you if you upgrade it..

question

دادا مگه auto complete text view همین کارو نمیکنه؟

Clear Field

How to Clear the text Field in spinner..??

Drop down of Spinner

While using in Fragment inside sub fragment it doesn't show drop down strange bugs help me out.. :(

Error inflating class ... FYI android.deliveryboy.com is name of my development project

Crash Log

2019-01-09 12:23:00.492 6982-6982/android.deliveryboy.com E/AndroidRuntime: FATAL EXCEPTION: main
Process: android.deliveryboy.com, PID: 6982
android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class android.deliveryboy.com.utils.AwesomeSpinner
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class android.deliveryboy.com.utils.AwesomeSpinner
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.deliveryboy.com.DeliveryHistory.onCreateView(DeliveryHistory.java:47)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #40: Binary XML file line #40: Error inflating class com.isapanah.awesomespinner.spinnerDefaultSelection
Caused by: android.view.InflateException: Binary XML file line #40: Error inflating class com.isapanah.awesomespinner.spinnerDefaultSelection
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.isapanah.awesomespinner.spinnerDefaultSelection" on path: DexPathList[[zip file "/data/app/android.deliveryboy.com-xeo6aBpNQOnNBlQiAKFzwg==/base.apk"],nativeLibraryDirectories=[/data/app/android.deliveryboy.com-xeo6aBpNQOnNBlQiAKFzwg==/lib/x86, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:23166)
at android.deliveryboy.com.utils.AwesomeSpinner.init(AwesomeSpinner.java:58)
2019-01-09 12:23:00.493 6982-6982/android.deliveryboy.com E/AndroidRuntime: at android.deliveryboy.com.utils.AwesomeSpinner.(AwesomeSpinner.java:49)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.deliveryboy.com.DeliveryHistory.onCreateView(DeliveryHistory.java:47)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

XML

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:orientation="vertical">



    <android.deliveryboy.com.utils.AwesomeSpinner
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:background="@drawable/spinner_bg" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:orientation="horizontal"
        android:weightSum="2">

        <Button
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:background="#F2F2F2"
            android:drawableLeft="@drawable/calenda"
            android:padding="7dp"
            android:text="DD / MM / YY"
            android:textColor="#B5B5B5" />


        <Button
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_marginLeft="3dp"
            android:layout_weight="1"
            android:background="#F2F2F2"
            android:drawableLeft="@drawable/calenda"
            android:padding="7dp"
            android:text="DD / MM / YY"
            android:textColor="#B5B5B5" />
    </LinearLayout>


</LinearLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:scrollbars="vertical"
    tools:listitem="@layout/current_deliveries_items" />

java code

package android.deliveryboy.com;

import android.app.ProgressDialog;
import android.deliveryboy.com.utils.AwesomeSpinner;
import android.deliveryboy.com.utils.Global;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import static android.deliveryboy.com.utils.Global.URL;

public class DeliveryHistory extends Fragment {

RecyclerView recyclerView;
android.support.v7.app.ActionBar actionBar;
ProgressDialog dialog;
View view;
String fromTimeStamp = "";
String toTimeStamp = "";
String cashMode="1";
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.delivery_history, container, false);


    actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    actionBar.setTitle("Delivery History");

    String[] arraySpinner = new String[] {"CASH", "ONLINE"};
    AwesomeSpinner s = (AwesomeSpinner) view.findViewById(R.id.spinner);
    
    return view;

}

Can you please help me into this ?

custom spinner_Item

سلام

برا استفاده از لایوت کاستوم خودمون طبق آموزش ها باید این قطعه کد استفاده بشه
ArrayAdapter <CharSequence> provincesAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.Month_array, R.layout.spinner_item); provincesAdapter.setDropDownViewResource(R.layout.spinner_item);

ولی با استفاده از این اسپینر نمیره از اون لایوتی که آدرس میدم استفاده کنه و فقط آرایه رو میره استفاده میکنه .

ممنون میشم راهنماییم کنین مشکل از کجاست

مرسی

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.