Thursday, March 1, 2012

Android auto fille textbox


This program is for auto fille textbox in android. Here i have given some word in program and if you type similar phase then it automatically give some option. 









Step 1)Your main java file is here
 

package a.b;
import org.xml.sax.Parser;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MytestandroidActivity extends Activity {
   
       /** Called when the activity is first created. */
      
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        TextView txt=(TextView) findViewById(R.id.txtURL);
        Linkify.addLinks(txt,Linkify.ALL);
       
        AutoCompleteTextView act=(AutoCompleteTextView)findViewById(R.id.act);
        ArrayAdapter arr=new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line,new String []{"Hello","Hi","Alloha"});
        act.setAdapter(arr);


       

              
       
    }
}

Step 2) Put below code in your main.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Visit Http://www.android-pro.blogspot.com"
    android:autoLink="web"
    android:id="@+id/txtURL"
    />

<AutoCompleteTextView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/act"
/>

</LinearLayout>

No comments:

Post a Comment