Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/FrederickRider/AutoCompleteBubbleText

Android AutoCompleteTextView with attached ListView, and drawable background
https://github.com/FrederickRider/AutoCompleteBubbleText

Last synced: 3 months ago
JSON representation

Android AutoCompleteTextView with attached ListView, and drawable background

Lists

README

        

## 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](https://github.com/FrederickRider/AutoCompleteBubbleText/blob/master/images/Screenshot_1.png)

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

![Sample image 2](https://github.com/FrederickRider/AutoCompleteBubbleText/tree/master/images/Screenshot_2.png)

## Usage

The sample activity shows a basic usage.

```xml


````````````````

Create some object that implements MultiSelectItem

```java
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:

```java
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 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() {

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

### You must call getListView():

```java
/**
* 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:

```java
/**
* Override this to return a custom ListView.
*/
ListView onCreateListView()
```

```java
/**
* Override this to return a custom Adapter,
* which (currently) must be an ArrayAdapter.
*/
ArrayAdapter 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 listener)
```