Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.crumbin.tabs;
- //import android.app.TabActivity;
- import java.util.ArrayList;
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.Editable;
- import android.widget.ArrayAdapter;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.text.TextWatcher;
- import com.crumbin.main.R;
- public class ExploreActivity extends Activity{
- private ListView lv;
- private EditText et;
- private String listview_array[] = { "Amit","Ashish","Guruji","Pandey gopal","Anirudh Khusape","Siddharth Menon","Alaskar","Summy Kapoor","Pardus",
- "Amit Savartkar","Shushil","Eldhose","Gopal"};
- private ArrayList<String> array_sort= new ArrayList<String>();
- int textlength=0;
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.explore_tab);
- lv = (ListView) findViewById(R.id.ListView01);
- et = (EditText) findViewById(R.id.EditText01);
- lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, listview_array));
- et.addTextChangedListener(new TextWatcher()
- {
- public void afterTextChanged(Editable s){
- // Abstract Method of TextWatcher Interface.
- }
- public void beforeTextChanged(CharSequence s,int start, int count, int after){
- // Abstract Method of TextWatcher Interface.
- }
- public void onTextChanged(CharSequence s,int start, int before, int count){
- textlength = et.getText().length();
- array_sort.clear();
- for (int i = 0; i < listview_array.length; i++){
- if (textlength <= listview_array[i].length()){
- if(et.getText().toString().equalsIgnoreCase((String)listview_array[i].subSequence(0,textlength)))
- {
- array_sort.add(listview_array[i]);
- }
- }
- }
- lv.setAdapter(new ArrayAdapter<String>(ExploreActivity.this,android.R.layout.simple_list_item_1, array_sort));
- }
- });
- }
- }
- /*
- XML > explore_tab.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout android:id="@+id/LinearLayout01"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical">
- <EditText android:id="@+id/EditText01"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:hint="Search">
- </EditText>
- <ListView android:id="@+id/ListView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" >
- </ListView>
- </LinearLayout>
- */
Advertisement
Add Comment
Please, Sign In to add comment