Saturday, August 1, 2015

Example of Auto Complete text in android

just drop auto-complete textview from widget to your layout or copy below code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
      >

        <requestFocus />
    </AutoCompleteTextView>

</LinearLayout>
 

Now open java file and paste below code 


package com.smr; //package name

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.app.Activity;

public class MainActivity extends Activity {
      String values[]={"January""July""June""Ravi","Ravinder""Abhishek""Abhinav""Harkishore""Hardev"};

      @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            AutoCompleteTextView lv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); 
//adapter will adapt the string and pass the string to lv object
            ArrayAdapter<?> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1values);
            lv.setAdapter(adapter);
            
      }
  }
 

No comments:

Post a Comment