Example usage for android.widget AutoCompleteTextView setAdapter

List of usage examples for android.widget AutoCompleteTextView setAdapter

Introduction

In this page you can find the example usage for android.widget AutoCompleteTextView setAdapter.

Prototype

public <T extends ListAdapter & Filterable> void setAdapter(T adapter) 

Source Link

Document

Changes the list of data used for auto completion.

Usage

From source file:de.spiritcroc.modular_remote.Util.java

public static void suggestPreviousIps(final Fragment fragment, final AutoCompleteTextView textView) {
    Activity activity = fragment.getActivity();
    final TcpConnectionManager tcpConnectionManager = TcpConnectionManager
            .getInstance(activity.getApplicationContext());
    textView.setAdapter(new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1,
            tcpConnectionManager.getConnectionSuggestions()));

    if (fragment instanceof ReceiverIpSelectorUser) {
        textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override/*from   w ww . j a va  2 s  .  com*/
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TcpConnectionManager.TcpConnection connection = tcpConnectionManager
                        .getTcpConnection(textView.getText().toString());
                ((ReceiverIpSelectorUser) fragment).setReceiverType(connection.getType());
            }
        });
    }
}

From source file:com.cairoconfessions.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView;/*from   w  w w  . j  a  va 2 s  .co  m*/
    switch (mPageNumber) {
    case 0:
        rootView = (ViewGroup) inflater.inflate(R.layout.fragment_location_screen_slide_page, container, false);
        adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line,
                COUNTRIES);
        adapter.setNotifyOnChange(true);
        AutoCompleteTextView textView = (AutoCompleteTextView) rootView.findViewById(R.id.addLocation);
        textView.setAdapter(adapter);
        break;
    case 1:
        rootView = (ViewGroup) inflater.inflate(R.layout.fragment_main_screen_slide_page, container, false);

        break;
    case 2:
        rootView = (ViewGroup) inflater.inflate(R.layout.fragment_category_screen_slide_page, container, false);

        break;
    default:
        rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false);
    }
    return rootView;
}

From source file:org.example.sinartweather.CityFinderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cityfinder_layout);
    AutoCompleteTextView edt = (AutoCompleteTextView) this.findViewById(R.id.edtCity);
    CityAdapter adpt = new CityAdapter(this, null);
    edt.setAdapter(adpt);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    edt.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from ww w .j  a  va  2 s . c o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CityResult result = (CityResult) parent.getItemAtPosition(position);
            SharedPreferences sharedPref = PreferenceManager
                    .getDefaultSharedPreferences(CityFinderActivity.this);
            //Log.d("SwA", "WOEID [" + result.getWoeid() + "]");
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("woeid", result.getWoeid());
            editor.putString("cityName", result.getCityName());
            editor.putString("country", result.getCountry());
            editor.commit();
            NavUtils.navigateUpFromSameTask(CityFinderActivity.this);
        }
    });
}

From source file:com.survivingwithandroid.weather.settings.CityFinderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cityfinder_layout);
    AutoCompleteTextView edt = (AutoCompleteTextView) this.findViewById(R.id.edtCity);
    CityAdapter adpt = new CityAdapter(this, null);
    edt.setAdapter(adpt);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    edt.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from   w w w.  j a v a 2s .  com*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CityResult result = (CityResult) parent.getItemAtPosition(position);
            SharedPreferences sharedPref = PreferenceManager
                    .getDefaultSharedPreferences(CityFinderActivity.this);
            //Log.d("SwA", "WOEID [" + result.getWoeid() + "]");
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("woeid", result.getWoeid());
            editor.putString("cityName", result.getCityName());
            editor.putString("country", result.getCountry());
            editor.commit();
            NavUtils.navigateUpFromSameTask(CityFinderActivity.this);
        }
    });

}

From source file:com.android.talkbacktests.testsession.StandardAndroidWidgetTest.java

@Override
public View getView(final LayoutInflater inflater, ViewGroup container, final Context context) {
    View view = inflater.inflate(R.layout.test_standard_android_widget, container, false);
    final Button contDescButton = (Button) view.findViewById(R.id.test_standard_android_widget_button2);
    contDescButton.setOnClickListener(new View.OnClickListener() {
        @Override/*w w  w  .j a va 2 s  .co  m*/
        public void onClick(View view) {
            mCount++;
            contDescButton.setContentDescription(getString(R.string.toast_content_changed_template, mCount));
        }
    });
    Button toastButton = (Button) view.findViewById(R.id.test_standard_android_widget_button3);
    toastButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(context, R.string.toast_expand_button_clicked, Toast.LENGTH_LONG).show();
        }
    });
    ViewCompat.setAccessibilityDelegate(toastButton, new AccessibilityDelegateCompat() {
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
                    AccessibilityNodeInfoCompat.ACTION_CLICK, getString(R.string.expand_button_action_label)));
        }
    });

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.city_array,
            android.R.layout.simple_spinner_item);

    Spinner spinner = (Spinner) view.findViewById(R.id.test_standard_android_widget_spinner);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    AutoCompleteTextView autocomplete = (AutoCompleteTextView) view
            .findViewById(R.id.test_standard_android_widget_autocomplete);
    autocomplete.setAdapter(adapter);

    mProgressBar = (ProgressBar) view.findViewById(R.id.test_standard_android_widget_progress_bar);
    mRunnable = new Runnable() {

        @Override
        public void run() {
            mProgressStatus += 5;
            mProgressBar.setProgress(mProgressStatus);
            if (mProgressStatus < 100) {
                mHandler.postDelayed(this, 1000);
            }
        }
    };
    resetProgressBar();

    View resetProgressBarButton = view.findViewById(R.id.test_standard_android_widget_reset_button);
    resetProgressBarButton.setOnClickListener(this);

    return view;
}

From source file:com.ibm.msg.android.NewConnection.java

/** 
 * @see android.app.Activity#onCreate(android.os.Bundle)
 *//*from  w ww. j a  v a 2 s.c  o m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_connection);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    adapter.addAll(readHosts());
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.serverURI);
    textView.setAdapter(adapter);

    //load auto compete options

}

From source file:edu.asu.msse.sgowdru.moviesqldb.SearchMovie.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_movie);
    info = new TextView[5];
    //In the info array of TextView type store id of each field
    info[0] = (TextView) findViewById(R.id.autoCompleteTextView);
    info[1] = (TextView) findViewById(R.id.editTitleSearch);
    info[2] = (TextView) findViewById(R.id.editGenreSearch);
    info[3] = (TextView) findViewById(R.id.editYearSearch);
    info[4] = (TextView) findViewById(R.id.editActorsSearch);

    //Ratings field is of type Spinner class with field values (PG, PG-13, R rated)
    dropdown = (Spinner) findViewById(R.id.spinnerSearch);
    adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dropdown.setAdapter(adapter);//from  www.  j a  v a2 s.co  m

    btn = (Button) findViewById(R.id.addSearch);

    context = getApplicationContext();
    duration = Toast.LENGTH_LONG;

    db = new MoviesDB(this);
    try {
        crsDB = db.openDB();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            gen);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.editGenreSearch);
    textView.setAdapter(adapter);
}

From source file:com.hardcopy.vcontroller.fragments.ControllerFragment.java

private void addAutoCompleteAdapter() {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1);
    adapter.addAll(Utils.getInstance(mContext).readSuggestion(Utils.AUTO_COMPLETE_TOPIC));
    AutoCompleteTextView textView = (AutoCompleteTextView) mRootView.findViewById(R.id.topic);
    textView.setAdapter(adapter);
}

From source file:com.example.android.downloadablefonts.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initializeSeekBars();/*from ww w .  j ava2  s . c om*/
    mFamilyNameSet = new ArraySet<>();
    mFamilyNameSet.addAll(Arrays.asList(getResources().getStringArray(R.array.family_names)));

    mDownloadableFontTextView = findViewById(R.id.textview);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.family_names));
    final TextInputLayout familyNameInput = findViewById(R.id.auto_complete_family_name_input);
    final AutoCompleteTextView autoCompleteFamilyName = findViewById(R.id.auto_complete_family_name);
    autoCompleteFamilyName.setAdapter(adapter);
    autoCompleteFamilyName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
            // No op
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int count, int after) {
            if (isValidFamilyName(charSequence.toString())) {
                familyNameInput.setErrorEnabled(false);
                familyNameInput.setError("");
            } else {
                familyNameInput.setErrorEnabled(true);
                familyNameInput.setError(getString(R.string.invalid_family_name));
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            // No op
        }
    });

    mRequestDownloadButton = findViewById(R.id.button_request);
    mRequestDownloadButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String familyName = autoCompleteFamilyName.getText().toString();
            if (!isValidFamilyName(familyName)) {
                familyNameInput.setErrorEnabled(true);
                familyNameInput.setError(getString(R.string.invalid_family_name));
                Toast.makeText(MainActivity.this, R.string.invalid_input, Toast.LENGTH_SHORT).show();
                return;
            }
            requestDownload(familyName);
            mRequestDownloadButton.setEnabled(false);
        }
    });
    mBestEffort = findViewById(R.id.checkbox_best_effort);
}

From source file:no.ntnu.idi.socialhitchhiking.map.AutoCompleteTextWatcher.java

/**
 * Sets the adapter for a given autocompletetextview
 * //from   w ww. ja  va2  s .c o m
 * @param list
 * @param autoCompleteTextView
 * @param needsHack This parameter is sometimes needed to get the correct event to trigger, if unsure, set to false
 */
private synchronized void setAutoCompleteArrayAdapter(final List<String> list,
        final AutoCompleteTextView autoCompleteTextView, boolean needsHack) {
    String[] data = list.toArray(new String[list.size()]);
    ArrayAdapter<?> adapter = new ArrayAdapter<Object>(context,
            no.ntnu.idi.socialhitchhiking.R.layout.item_list, data);
    autoCompleteTextView.setAdapter(adapter);

    if (needsHack) {
        int selStartF = autoCompleteTextView.getSelectionStart();
        int selStopF = autoCompleteTextView.getSelectionEnd();
        autoCompleteTextView.setText(autoCompleteTextView.getText().toString() + "");
        autoCompleteTextView.setText(autoCompleteTextView.getText().toString().replace("", ""));
        autoCompleteTextView.setSelection(selStartF, selStopF);
    }
}