Coder Social home page Coder Social logo

autocompletebubbletext's Introduction

Notes

AutoCompleteBubbleText allows you to add and remove items from an EditText using a drawable as a background.

The benefit of AutoCompleteBubbleText is that you can position the ListView anywhere in the layout instead of just under the EditText.

You can also use the autocomplete filtering function of the EditText to filter items in the list.

An example use is in contact lists that need to be filtered and keep checked states.

Sample image 1

You can also filter the list by text after the last delimiter:

Sample image 2

Usage

The sample activity shows a basic usage.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.mycardboarddreams.autocompletebubbletext.MultiSelectEditText
        android:id="@+id/auto_text_complete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:padding="5dp"
        android:background="#FFEEEEEE"/>

    <!-- Layout where the list will go -->
    <FrameLayout
        android:id="@+id/auto_list_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#FF666666"/>

</LinearLayout>

Create some object that implements MultiSelectItem

public class SampleItem implements MultiSelectItem {

    private final String mReadableName;
    private final String mId;

    public SampleItem(String readableName){
        mReadableName = readableName;
        mId = String.valueOf(readableName.hashCode());
    }

    @Override
    public String getId() {
        return mId;
    }

    @Override
    public String getReadableName() {
        return mReadableName;
    }

    @Override
    public String toString() {
        return mReadableName;
    }
}

Once you've set up the layout, pull the ListView out of the EditText, and put it wherever in the layout you like:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);

    //Find the MultiSelectEditText in the layout
    MultiSelectEditText editText = (MultiSelectEditText)findViewById(R.id.auto_text_complete);

    /**
     * Add some sample items
     * The type of item can be anything that implements MultiSelectItem
     */
    List<SampleItem> sampleItems = Arrays.asList(
            new SampleItem("Aaron LastName"),
            new SampleItem("Cameron Chimes"),
            new SampleItem("Tim Gibbons"),
            new SampleItem("Gary Styles"),
            new SampleItem("Bart Thompson"),
            new SampleItem("Abagail B.D.E.")
    );

    editText.addAllItems(sampleItems);

    //Pull out the ListView from the MultiSelectEditText
    ListView list = editText.getListView();

    //Add it to a ViewGroup somewhere else in the layout
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    list.setLayoutParams(params);

    FrameLayout frame = (FrameLayout)findViewById(R.id.auto_list_container);
    frame.addView(list);

    //Set a listener on bubble clicks
    editText.setBubbleClickListener(new MultiSelectEditText.BubbleClickListener<SampleItem>() {

        @Override
        public void onClick(SampleItem item) {
            Log.d(TAG, "Item: " + item.getReadableName());
        }
    });
}

You must call getListView():

/**
 * Once the ListView is created, you must fetch
 * it and add it as a child of some other layout.
 */
ListView getListView()

Customization

You can customize most parts of the view.

You may also override the following methods:

/**
 * Override this to return a custom ListView.
 */
ListView onCreateListView()
/**
 * Override this to return a custom Adapter,
 * which (currently) must be an ArrayAdapter.
 */
ArrayAdapter<T> onCreateAdapter()

/**
 * Override this to return the resource
 * representing the bubble drawable.
 */
int getBubbleResource()


/**
 * Override this to return a different delimiter string.
 */
String getDelimiter()

/**
 * Override this to return filtered results given the last value
 * after the delimiter (default is ','), lastCommaValue.
 */
filterData(String lastCommaValue)

/**
 * Call this to pass a listener for clicks on bubbles
 * Pass in a class that implements BubbleClickListener
 */
setBubbleClickListener(BubbleClickListener<T> listener)

autocompletebubbletext's People

Contributors

frederickrider avatar ravidsrk avatar

Stargazers

Wait until dark avatar  avatar Shiiyuko avatar  avatar  avatar  avatar Wendy avatar xiaoyao avatar  avatar yuchao.wang avatar Alex Neo avatar Harish Uginval avatar  avatar 爱玩 avatar  avatar Vitaliy avatar Arjun Sunil Kumar avatar  avatar wangshenglongrc avatar 陈飞 avatar  avatar  avatar Simon McDonnell avatar  avatar clodthunder avatar Yang Feng avatar  avatar dy avatar Michael Hsu avatar  avatar Spring avatar  avatar Jungle avatar WilsonL avatar  avatar Igor Morais avatar  Thunder Double avatar  avatar Pritesh Patel avatar  avatar  avatar whamu2 avatar Andy avatar  avatar  avatar Sincere Xie avatar luoj avatar Iaouei avatar / avatar xujun wu avatar  avatar yoon avatar Wenhao Ding avatar Oleg Martemjanov avatar Jack Hoang avatar Pranav Lathigara avatar  avatar huynh duong quang avatar Eminem Lo avatar  avatar cocoa avatar Milo avatar  avatar  avatar 张亚飞 avatar zhengjiong avatar  avatar william avatar droplet avatar Royce Zhang avatar 佳平 avatar panpf avatar Jerry avatar Evan Leis avatar davidwei_001 avatar Derek avatar AiYoYo avatar Victor Sopilko avatar  avatar  avatar SeniorZhai avatar Ren  Yu avatar Ian Lee avatar youxiachai avatar wuqingman avatar SherlockHolmes avatar  avatar 朱杰 avatar  avatar  avatar guobangbang avatar magh avatar 尚晓东 avatar LiqiangZhang avatar  avatar lr avatar 番茄炒蛋 avatar 睦毅 avatar Yossi Elkrief avatar 李小义 avatar

Watchers

davidwei_001 avatar william avatar felixchen avatar  avatar Zhe Chen avatar Ren  Yu avatar  avatar  avatar  avatar

autocompletebubbletext's Issues

Add multiple elements at a time

I have one arraylist of my models. I want to add all the items from my arraylist to multiedit text so I will iterate the list using for loop, but at that time my application crashed. I got following crash:

05-27 15:33:19.737: E/AndroidRuntime(25597): java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1023)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:611)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:607)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.text.Selection.setSelection(Selection.java:76)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.text.Selection.setSelection(Selection.java:87)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.widget.Editor.onTouchUpEvent(Editor.java:1616)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.widget.TextView.onTouchEvent(TextView.java:8006)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.view.View.dispatchTouchEvent(View.java:8393)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
05-27 15:33:19.737: E/AndroidRuntime(25597): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)

Please suggest any solution on the same.

Invisible selected entries

I am adding too much entries. After Adding new entry some time previous entries are invisible. Please suggest the solution on that...

How to get strings of the chosen items

Hey, How can i get strings of the chosen items so i can use them later
ex ( if output(items chosen) = "BLAH BLAH, BLAH BLAH") {set text." Another text"}

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.