Code Monkey home page Code Monkey logo

edit-spinner's Introduction

EditSpinner

An EditText which supports spinner FOR API LEVEL >= 11



[Download Demo APK](https://github.com/xyxyLiu/Edit-Spinner/releases/download/1.1.0/EditSpinner-Demo-1.1.apk)

Gradle Dependency

Download

repositories {
    ...
    jcenter()
}

dependencies {
    implementation 'com.reginald:editspinner:1.1.0'
}

Usage

  • add EditSpinner in xml
<com.reginald.editspinner.EditSpinner
        android:id="@+id/edit_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:dropDownDrawable="@drawable/spinner_icon"
        app:dropDownDrawableSpacing="15dp"
        app:dropDownDrawableWidth="25dp"
        app:dropDownDrawableHeight="25dp"
        />
  • setup datas using Adapter
        mEditSpinner = (EditSpinner) findViewById(R.id.edit_spinner);
        ListAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
        getResources().getStringArray(R.array.your_string_array));
        mEditSpinner.setAdapter(adapter);

key properties:

attr required/optional(default value) meaning
dropDownDrawable required dropdown drawable shown on the right of the EditText
dropDownDrawableWidth optional, default using drawable intrinsic width width of dropdown drawable
dropDownDrawableHeight optional, default using drawable intrinsic height height of dropdown drawable
dropDownDrawableSpacing optional, default is 0 the spacing between edittext area and dropdown drawable area

More Usages

  • config editable

In some cases, you want to make it uneditable. You can

use android:editable in xml to disable editable:

android:editable="false"

or set it dynamically:

mEditSpinner.setEditable(false);
  • config dropdown window
        // set the dropdown drawable on the right of EditText and its size
        mEditSpinner.setDropDownDrawable(getResources().getDrawable(R.drawable.picker), 60, 60);

        // set the spacing bewteen Edited area and DropDown click area
        mEditSpinner.setDropDownDrawableSpacing(50);

        // set DropDown popup window background
        mEditSpinner.setDropDownBackgroundResource(R.drawable.your_custom_dropdown_bkg);

        // set DropDown animation of the popup window
        mEditSpinner.setDropDownAnimationStyle(R.style.CustomPopupAnimation);
  • config listeners
        // triggered when dropdown popup window dismissed
        mEditSpinner.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
            }
        });

        // triggered when dropdown popup window shown
        mEditSpinner.setOnShowListener(new EditSpinner.OnShowListener() {
            @Override
            public void onShow() {
            }
        });

        // it converts the item in the list to a string shown in EditText.
        mEditSpinner.setItemConverter(new EditSpinner.ItemConverter() {
            @Override
            public String convertItemToString(Object selectedItem) {
            }
        });

        // triggered when one item in the list is clicked
        mEditSpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            }
        });

License

Copyright 2019 xyxyLiu

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 License.

edit-spinner's People

Contributors

reginaldliu avatar xyxyliu avatar

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.