Giter VIP home page Giter VIP 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);
}

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)

autocompletebubbletext's People

Watchers

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