FileDocCategorySizeDatePackage
AutoCompleteTextViewSimple.javaAPI DocAndroid 5.1 API3977Thu Mar 12 22:22:12 GMT 2015android.widget

AutoCompleteTextViewSimple

public class AutoCompleteTextViewSimple extends android.app.Activity implements android.widget.AdapterView.OnItemClickListener, android.widget.AdapterView.OnItemSelectedListener

Fields Summary
private final String
LOG_TAG
private AutoCompleteTextView
mTextView
public boolean
mItemClickCalled
These are cleared by resetItemListeners(), and set by the callback listeners
public int
mItemClickPosition
public boolean
mItemSelectedCalled
public int
mItemSelectedPosition
public boolean
mNothingSelectedCalled
Constructors Summary
Methods Summary
public AutoCompleteTextViewgetTextView()

return
The AutoCompleteTextView used in this test activity.

        return mTextView;
    
protected voidonCreate(android.os.Bundle icicle)


    
       
    
        // Be sure to call the super class.
        super.onCreate(icicle);

        // setup layout & views
        setContentView(R.layout.autocompletetextview_simple);
        mTextView = (AutoCompleteTextView) findViewById(R.id.autocompletetextview1);
        
        // configure callbacks used for monitoring
        mTextView.setOnItemClickListener(this);
        mTextView.setOnItemSelectedListener(this);
        resetItemListeners();
        
        setStringAdapter(5, "a");
    
public voidonItemClick(AdapterView parent, android.view.View view, int position, long id)
Implements OnItemClickListener

        Log.d(LOG_TAG, "onItemClick() position " + position);
        mItemClickCalled = true;
        mItemClickPosition = position;
    
public voidonItemSelected(AdapterView parent, android.view.View view, int position, long id)
Implements OnItemSelectedListener

        Log.d(LOG_TAG, "onItemSelected() position " + position);
        mItemSelectedCalled = true;
        mItemSelectedPosition = position;
    
public voidonNothingSelected(AdapterView parent)
Implements OnItemSelectedListener

        Log.d(LOG_TAG, "onNothingSelected()");
        mNothingSelectedCalled = true;
    
public voidresetItemListeners()
For monitoring OnItemClickListener & OnItemSelectedListener An alternative here would be to provide a set of pass-through callbacks

        mItemClickCalled = false;
        mItemClickPosition = -1;
        mItemSelectedCalled = false;
        mItemSelectedPosition = -1;
        mNothingSelectedCalled = false;
    
public voidsetStringAdapter(int numSuggestions, java.lang.String prefix)
Set the autocomplete data to an adapter containing 0..n strings with a consistent prefix.

        // generate the string array
        String[] strings = new String[numSuggestions];
        for (int i = 0; i < numSuggestions; ++i) {
            strings[i] = prefix + String.valueOf(i);
        }
        
        // install it with an adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, strings);
        mTextView.setAdapter(adapter);