android.widget.AutoCompleteTextView.setAdapter()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中android.widget.AutoCompleteTextView.setAdapter()方法的一些代码示例,展示了AutoCompleteTextView.setAdapter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AutoCompleteTextView.setAdapter()方法的具体详情如下:
包路径:android.widget.AutoCompleteTextView
类名称:AutoCompleteTextView
方法名:setAdapter

AutoCompleteTextView.setAdapter介绍

暂无

代码示例

代码示例来源:origin: rey5137/material

/**
 * <p>Changes the list of data used for auto completion. The provided list
 * must be a filterable list adapter.</p>
 *
 * <p>The caller is still responsible for managing any resources used by the adapter.
 * Notably, when the AutoCompleteTextView is closed or released, the adapter is not notified.
 * A common case is the use of {@link CursorAdapter}, which
 * contains a {@link android.database.Cursor} that must be closed.  This can be done
 * automatically (see
 * {@link android.app.Activity#startManagingCursor(android.database.Cursor)
 * startManagingCursor()}),
 * or by manually closing the cursor when the AutoCompleteTextView is dismissed.</p>
 *
 * <p>Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}</p>
 *
 * @param adapter the adapter holding the auto completion data
 *
 * @see #getAdapter()
 * @see Filterable
 * @see ListAdapter
 */
public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
  if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE)
    return;
  ((AutoCompleteTextView)mInputView).setAdapter(adapter);
}

代码示例来源:origin: googlesamples/android-testing

/**
   * Creates an adapter and sets it to an {@link AutoCompleteTextView} to enable suggestions.
   */
  private void setUpAutoCompleteTextView() {
    String[] completions = getResources().getStringArray(R.array.bodies_of_water);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
        this,
        android.R.layout.simple_dropdown_item_1line,
        completions);

    AutoCompleteTextView autoComplete =
        (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
    autoComplete.setAdapter(adapter);
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle state) {
 super.onCreate(state);
 setContentView(R.layout.main);
 selection=(TextView)findViewById(R.id.selection);
 edit=(AutoCompleteTextView)findViewById(R.id.edit);
 edit.addTextChangedListener(this);
 
 edit.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line,
            items));
}

代码示例来源:origin: aporter/coursera-android

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

    String[] mCountries = getResources().getStringArray(R.array.country_names);

    // Get a reference to the AutoCompleteTextView
    final AutoCompleteTextView textView = findViewById(R.id.autocomplete_country);

    // Create an ArrayAdapter containing country names
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
        R.layout.list_item, mCountries);

    // Set the adapter for the AutoCompleteTextView
    textView.setAdapter(adapter);

    // Display a Toast Message when the user clicks on an item in the AutoCompleteTextView
    textView.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> arg0, View view, int arg2,
                  long arg3) {
        Toast.makeText(getApplicationContext(),
            getString(R.string.winner_is_string, arg0.getAdapter().getItem(arg2)),
            Toast.LENGTH_LONG).show();
        textView.setText("");
      }
    });
  }
}

代码示例来源:origin: stackoverflow.com

mSearchAutoComplete.setAdapter(adapter);

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldInvokeFilter() throws Exception {
 Robolectric.getForegroundThreadScheduler().pause();
 AutoCompleteTextView view =
   new AutoCompleteTextView(ApplicationProvider.getApplicationContext());
 view.setAdapter(adapter);
 view.setText("Foo");
 assertThat(adapter.getCount()).isEqualTo(2);
}

代码示例来源:origin: lincanbin/Android-Carbon-Forum

private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
  //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
  ArrayAdapter<String> adapter =
      new ArrayAdapter<>(RegisterActivity.this,
          android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
  mEmailView.setAdapter(adapter);
}

代码示例来源:origin: AppLozic/Applozic-Android-SDK

private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
  //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
  ArrayAdapter<String> adapter =
      new ArrayAdapter<String>(LoginActivity.this,
          android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
  mEmailView.setAdapter(adapter);
}

代码示例来源:origin: KingsMentor/IntentManip

private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
  //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
  ArrayAdapter<String> adapter =
      new ArrayAdapter<>(Sample.this,
          android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
  mEmailView.setAdapter(adapter);
}

代码示例来源:origin: cheng2016/AndroidUIAdapter

private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
  //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
  ArrayAdapter<String> adapter =
      new ArrayAdapter<>(LoginActivity.this,
          android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
  mEmailView.setAdapter(adapter);
}

代码示例来源:origin: tyzlmjj/AndroidUI

private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
  //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
  ArrayAdapter<String> adapter =
      new ArrayAdapter<>(LoginActivity.this,
          android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
  mEmailView.setAdapter(adapter);
}

代码示例来源:origin: iTXTech/Daedalus

textViewTestDomain.setAdapter(autoCompleteArrayAdapter);

代码示例来源:origin: stackoverflow.com

AutoCompleteTextView tvSuburbs;
ArrayAdapter<Suburb> a = (ArrayAdapter<Suburb>) tvSuburbs.getAdapter();
tvSuburbs.setAdapter(null); // Remove the adapter so we don't get a dropdown
tvSuburbs.setText(s.name); // when text is set programmatically.
tvSuburbs.setAdapter(a); // Restore adapter

代码示例来源:origin: cyclestreets/android

private RouteByNumberCallbacks(final Context context,
                final AlertDialog.Builder builder) {
 this.context = context;
 final View layout = View.inflate(context, R.layout.routenumber, null);
 builder
  .setView(layout)
  .setPositiveButton(R.string.load_route, MessageBox.NoAction);
 numberText = layout.findViewById(R.id.routeNumber);
 history = new EditTextHistory(context, "RouteNumber");
 numberText.setAdapter(history);
 routeType = layout.findViewById(R.id.routeType);
}

代码示例来源:origin: li2/learning-android-open-source

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

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

代码示例来源:origin: posm/OpenMapKitAndroid

private void setupAutoComplete() {
  Set<String> tagValues = OSMDataSet.tagValues();
  String[] tagValuesArr = tagValues.toArray(new String[tagValues.size()]);
  ArrayAdapter<String> adapter = new ArrayAdapter<>(this.getActivity(),
      android.R.layout.simple_dropdown_item_1line, tagValuesArr);
  tagValueEditText.setAdapter(adapter);
  tagValueEditText.setThreshold(1);
}

代码示例来源:origin: wasdennnoch/AndroidN-ify

public NameAutoCompletePreference(Context context, AttributeSet attrs) {
  super(context, attrs);
  try {
    getAutoCompleteTextView().setAdapter(createAdapter());
  } catch (Throwable ignore) {
  }
}

代码示例来源:origin: THEONE10211024/ApiDemos

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.autocomplete_4);
  ContentResolver content = getContentResolver();
  Cursor cursor = content.query(Contacts.CONTENT_URI,
      CONTACT_PROJECTION, null, null, null);
  ContactListAdapter adapter = new ContactListAdapter(this, cursor);
  AutoCompleteTextView textView = (AutoCompleteTextView)
      findViewById(R.id.edit);
  textView.setAdapter(adapter);
}

代码示例来源:origin: henrichg/PhoneProfilesPlus

private void filterOnString(String string) {
    if (mAutoCompleteTextView.getAdapter() == null) {
      mAutoCompleteTextView.setAdapter(mFilterAdapter);
    }
    mHideFilterSearchOnStart = false;
    mFilterAdapter.getFilter().filter(string);
  }
}

代码示例来源:origin: pchauhan/AutoCompleteEditTextWithContact

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  mEdtPhoneNumber = (EditText)findViewById(R.id.edtPhoneNumber);
  mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
  mContactAdapter =  new ContactAdapter(this ,R.layout.contact_list_item,arrContact);
  mAutoCompleteTextView.setThreshold(1);
  mAutoCompleteTextView.setAdapter(mContactAdapter);
}
public ArrayList<Contact_Object> getPhoneNumber(String name, Context context) {

相关文章

AutoCompleteTextView类方法