Feb 26, 2013

Android Chips EditText , Token EditText and Bubble EditText [Part 2]

Since I write first previous blog on Chips Edit Text, many developer ask me to make chips edit text as library so they can integrate easily in the project, so I develop Chips Edit Text as library.

Android Chips EditText , Token EditText and Bubble EditText - [Part 1]

Github url : https://github.com/kpbird/chips-edittext-library

Github as two sub folders namely 1. ChipsEditTextLibrary 2. ChipsEditTextDemo

How to use library ?

Step 1: Clone git repor or download zip file

Step 2: Import ChipsEditTextLibrary in your eclipse workspace

Step 3: Create new Android project

Step 4: Set ChipsEditTextLibrary as reference of your project

Right Click on Project -> Properties -> Android ->Add

Step 4: Open your xml layout file and add ChipsEditText control
        android:text="" >

        <requestFocus />

Step 5: Open your Activity class and write following code. 

package com.kpbird.chipsedittextdemo;

import java.util.ArrayList;
import android.app.Activity;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.Log;

import com.kpbird.chipsedittextlibrary.ChipsAdapter;
import com.kpbird.chipsedittextlibrary.ChipsItem;
import com.kpbird.chipsedittextlibrary.ChipsMultiAutoCompleteTextview;

public class MainActivity extends Activity {

 protected void onCreate(Bundle savedInstanceState) {

  ChipsMultiAutoCompleteTextview ch = (ChipsMultiAutoCompleteTextview) findViewById(R.id.chipsMultiAutoCompleteTextview1);

  String[] countries = getResources().getStringArray(R.array.country);
  TypedArray imgs = getResources().obtainTypedArray(R.array.flags);

  ArrayList<ChipsItem> arrCountry = new ArrayList<ChipsItem>();

  for (int i = 0; i < countries.length; i++) {
   arrCountry.add(new ChipsItem(countries[i], imgs
     .getResourceId(i, -1)));
   Log.i("Main Activity", arrCountry.get(i).getTitle() + " = "
     + arrCountry.get(i).getImageid());

  Log.i("MainActivity", "Array :" + arrCountry.size());

  ChipsAdapter chipsAdapter = new ChipsAdapter(this, arrCountry);



Step 6: You need to use ChipsItem and ChipsAdapter to provide data. ChipsItem has two field 1. Title and 2. Image Id (R.drawable.android), In above sample I have created two array in string.xml for title and images.