AutoCompleteBubbleText


Source link: https://github.com/FrederickRider/AutoCompleteBubbleText

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.

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

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)

Resources

FontIcon is a simple library which allows to use font-based icons in Android.

Xdroid - extensions library for any Android app.

An Android image processor library providing a variety of transformations for Fresco.

Android MVVM lightweight library.

Implementation of Facebook social plugin 'Like' for Android.

A simple library to add tooltips to your awesome Android application.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes