PowenKo, Android, Tutorial 014, UI, AutoCompleteTextView


 

<?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="@string/hello"
    />

<AutoCompleteTextView android:id="@+id/autoCompleteTextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>    
    
</LinearLayout>

 

package com.powenko.Tutorial_UI_AutoCompleteTextView;


import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

public class Tutorial_UI_AutoCompleteTextViewActivity extends Activity {
	
	AutoCompleteTextView myAutoComplete;
	String item[]={
	  "January", "February", "March", "April",
	  "May", "June", "July", "August",
	  "September", "October", "November", "December",
          "PowenKo","PowenKo.com"
	};


	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         
        
        myAutoComplete = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
        
        myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, item));
        

        myAutoComplete.addTextChangedListener(new TextWatcher() {
        	 
            public void afterTextChanged(Editable s) {
              //  ((TextView)findViewById(R.id.numcaratteri)).setText(String.format(getString(R.string.caratteri), s.length()));
         
            }
         
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
         
            }
         
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub
         
            }
         
        });
        
    }
}

 

 

 

 

 

 

 

 

 

 

 

sample code:

Tutorial_UI_AutoCompleteTextViewActivity


Leave a Reply