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

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

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

AutoCompleteTextView.setOnItemClickListener介绍

暂无

代码示例

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

/**
 * <p>Sets the listener that will be notified when the user clicks an item
 * in the drop down list.</p>
 * <p>Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}</p>
 *
 * @param l the item click listener
 */
public void setOnItemClickListener(AdapterView.OnItemClickListener l) {
  if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE)
    return;
  ((AutoCompleteTextView)mInputView).setOnItemClickListener(l);
}

代码示例来源: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.setOnItemClickListener(listener);

代码示例来源:origin: andforce/iBeebo

public AutoCompleteAdapter(Activity context, AutoCompleteTextView content, ProgressBar pb) {
  super(context, android.R.layout.simple_list_item_1);
  data = new ArrayList<AtUserBean>();
  this.activity = context;
  this.res = android.R.layout.simple_list_item_1;
  this.pb = pb;
  this.content = content;
  this.content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      String searchFetchedWord = getItem(position).getNickname();
      int searchFetchedWordLength = searchFetchedWord.length();
      int calcResultSelectionPosition = atSignPosition + searchFetchedWordLength;
      AutoCompleteAdapter.this.content.setSelection(calcResultSelectionPosition + 2);
    }
  });
}

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

AutoCompleteTextView inputSearch=(AutoCompleteTextView) view.findViewById(R.id.inputSearch);
 products = new String[]{"Product1","product2","product3"}; 
 inputSearch.setAdapter(new ArrayAdapter<String>(getActivity(),R.layout.listitem,products));
 inputSearch.setThreshold(1);
 inputSearch.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
     inputSearch.showDropDown();
   }
 });
 inputSearch.setOnItemClickListener(new OnItemClickListener(){
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
   //Do whatever you want with selected object
   }
  }

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

public class myActivity extends Activity implements OnItemClickListener {

  AutoCompleteTextView mEditTextInput;

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mEditTextInput = (AutoCompleteTextView)layout.findViewById(R.id.edtx_input);
    mEditTextInput.setOnItemClickListener(this);
  }

  public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
    Console.debug(TAG, "view: " + arg1, Console.Liviu);             
    mEditTextInput.setText(((FormOption)mEditTextInput.getAdapter().getItem(position)).getDescription());
  }
}

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

private AutoCompleteTextView mAutoText;

 mAutoText.setOnTouchListener(new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        mAutoText.showDropDown();
        mAutoText.setListSelection(mPos);
        return false;
      }

    });
mAutoText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      mAdapter.setSelection(position);
      mPos = position;

    }
  });

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

autocomplete_searchField.setOnItemClickListener(new AdapterView.OnItemClickListener() {

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

mAutoCompleteTextView.setTypeface(mSansSerifLightTypeface);
mAutoCompleteTextView.addTextChangedListener(this);
mAutoCompleteTextView.setOnItemClickListener(this);
mAutoCompleteTextView.setOnClickListener(this);

代码示例来源:origin: p-v/DateTimeSeer

autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

代码示例来源:origin: playerone-id/EosCommander

private void setupAccountHistory(){
  // get abi when contract name item selected
  mEtContract.setOnItemClickListener( (adapterView, view, position, id) -> {
    ListAdapter adapter = mEtContract.getAdapter();
    if ( (null != adapter ) && !StringUtils.isEmpty( (String) adapter.getItem(position)) ){
      onContractEntered( (String) adapter.getItem(position) );
    }
  });
  UiUtils.setupAccountHistory( mEtContract, mEtPermissionAccount );
}

代码示例来源:origin: playerone-id/EosCommander

private void setupAccountHistory(){
  UiUtils.setupAccountHistory(mScope, mTvCode);
  // when contract selected
  mTvCode.setOnItemClickListener( (adapterView, view, position, id) -> {
    ListAdapter adapter = mTvCode.getAdapter();
    if ( (null != adapter ) && !StringUtils.isEmpty( (String) adapter.getItem(position)) ){
      hideKeyboard();
      mPresenter.onGetTableListClicked( (String) adapter.getItem(position) );
    }
  });
}

代码示例来源:origin: dsolonenko/financisto

private void initAutoCompleteFilter(final AutoCompleteTextView filterTxt) { // init only after it's toggled
  autoCompleteAdapter = TransactionUtils.createCategoryFilterAdapter(activity, db);
  filterTxt.setInputType(InputType.TYPE_CLASS_TEXT 
          | InputType.TYPE_TEXT_FLAG_CAP_WORDS 
          | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
          | InputType.TYPE_TEXT_VARIATION_FILTER);
  filterTxt.setThreshold(1);
  filterTxt.setOnFocusChangeListener((view, hasFocus) -> {
    if (hasFocus) {
      filterTxt.setAdapter(requireNonNull(autoCompleteAdapter));
      filterTxt.selectAll();
    }
  });
  filterTxt.setOnItemClickListener((parent, view, position, id) -> {
    activity.onSelectedId(R.id.category, id);
    ToggleButton toggleBtn = (ToggleButton) filterTxt.getTag();
    toggleBtn.performClick();
  });
}

代码示例来源:origin: stripe/stripe-android

private void initView() {
  inflate(getContext(), R.layout.country_autocomplete_textview, this);
  mCountryAutocomplete = findViewById(R.id.autocomplete_country_cat);
  mCountryNameToCode = CountryUtils.getCountryNameToCodeMap();
  final ArrayAdapter countryAdapter = new CountryAdapter(getContext(),
      new ArrayList<>(mCountryNameToCode.keySet()));
  mCountryAutocomplete.setThreshold(0);
  mCountryAutocomplete.setAdapter(countryAdapter);
  mCountryAutocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
      String countryEntered = mCountryAutocomplete.getText().toString();
      updateUIForCountryEntered(countryEntered);
    }
  });
  String defaultCountryEntered = (String) countryAdapter.getItem(0);
  updateUIForCountryEntered(defaultCountryEntered);
  mCountryAutocomplete.setText(defaultCountryEntered);
  mCountryAutocomplete.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean focused) {
      String countryEntered = mCountryAutocomplete.getText().toString();
      if (focused) {
        mCountryAutocomplete.showDropDown();
      } else {
        updateUIForCountryEntered(countryEntered);
      }
    }
  });
}

代码示例来源:origin: xbenjii/PokeMock

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  storage = new SharedPreferencesStorage(this);
  lastLocation = storage.getLastCoordinates();
  mGoogleApiClient = new GoogleApiClient.Builder(this)
      .enableAutoManage(this, 0 /* clientId */, this)
      .addApi(Places.GEO_DATA_API)
      .build();
  // Retrieve the AutoCompleteTextView that will display Place suggestions.
  mAutocompleteView = (AutoCompleteTextView)
      findViewById(R.id.autocomplete_places);
  // Register a listener that receives callbacks when a suggestion has been selected
  mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener);
  mAdapter = new PlaceAutocompleteAdapter(this, mGoogleApiClient, null,
      null);
  mAutocompleteView.setAdapter(mAdapter);
  button = (Button) findViewById(R.id.button);
  button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      // Start app
      startOverlay();
    }
  });
  SupportMapFragment mapFragment =
      (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
  mapFragment.getMapAsync(this);
}

代码示例来源:origin: tangqi92/MyGooglePlaces

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // Construct a GoogleApiClient for the {@link Places#GEO_DATA_API} using AutoManage
  // functionality, which automatically sets up the API client to handle Activity lifecycle
  // events. If your activity does not extend FragmentActivity, make sure to call connect()
  // and disconnect() explicitly.
  mGoogleApiClient = new GoogleApiClient.Builder(this)
      .enableAutoManage(this, GOOGLE_API_CLIENT_ID /* clientId */, this)
      .addApi(Places.GEO_DATA_API)
      .addApi(Places.PLACE_DETECTION_API)
      .build();
  setContentView(R.layout.activity_main);
  // Retrieve the AutoCompleteTextView that will display Place suggestions.
  mAutocompleteView = (AutoCompleteTextView)
      findViewById(R.id.autocomplete_places);
  // Register a listener that receives callbacks when a suggestion has been selected
  mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener);
  // Retrieve the TextViews that will display details and attributions of the selected place.
  mPlaceDetailsText = (TextView) findViewById(R.id.place_details);
  mPlaceDetailsAttribution = (TextView) findViewById(R.id.place_attribution);
  // CurrentLocation
  mCurrentLocation = (Button) findViewById(R.id.btn_current_location);
  mCurrentLocation.setOnClickListener(mOnClickListener);
  // Set up the adapter that will retrieve suggestions from the Places Geo Data API that cover
  // the entire world.
  mAdapter = new PlaceAutocompleteAdapter(this, android.R.layout.simple_list_item_1,
      mGoogleApiClient, BOUNDS_GREATER_SYDNEY, null);
  mAutocompleteView.setAdapter(mAdapter);
}

代码示例来源:origin: tangqi92/BuildingBlocks

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  ButterKnife.bind(this);
  App.addActivity(this);
  // Construct a GoogleApiClient for the {@link Places#GEO_DATA_API} using AutoManage
  // functionality, which automatically sets up the API client to handle Activity lifecycle
  // events. If your activity does not extend FragmentActivity, make sure to call connect()
  // and disconnect() explicitly.
  mGoogleApiClient = new GoogleApiClient.Builder(this)
      .enableAutoManage(this, GOOGLE_API_CLIENT_ID /* clientId */, this)
      .addApi(Places.GEO_DATA_API)
      .addApi(Places.PLACE_DETECTION_API)
      .build();
  setTitle(getString(R.string.title_pick_place));
  // Register a listener that receives callbacks when a suggestion has been selected
  mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener);
  mCurrentLocation.setOnClickListener(mOnClickListener);
  // Set up the adapter that will retrieve suggestions from the Places Geo Data API that cover
  // the entire world.
  mAdapter = new GooglePlacesAdapter(this, android.R.layout.simple_list_item_1,
      mGoogleApiClient, BOUNDS_GREATER_SYDNEY, null);
  mAutocompleteView.setAdapter(mAdapter);
  mSwipeBackLayout = getSwipeBackLayout();
  mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
}

代码示例来源:origin: dsolonenko/financisto

private void initAutoCompleteFilter(final AutoCompleteTextView filterTxt) {
  filterAdapter = createFilterAdapter();
  filterTxt.setInputType(InputType.TYPE_CLASS_TEXT
      | InputType.TYPE_TEXT_FLAG_CAP_WORDS
      | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
      | InputType.TYPE_TEXT_VARIATION_FILTER);
  filterTxt.setThreshold(1);
  filterTxt.setOnFocusChangeListener((view, hasFocus) -> {
    if (hasFocus) {
      filterTxt.setAdapter(filterAdapter);
      filterTxt.selectAll();
    }
  });
  filterTxt.setOnItemClickListener((parent, view, position, id) -> {
    activity.onSelectedId(layoutId, id);
    ToggleButton toggleBtn = (ToggleButton) filterTxt.getTag();
    toggleBtn.performClick();
  });
}

代码示例来源:origin: zadr50/Gojek

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_place_find);
  mTextView = (TextView) findViewById( R.id.textview );
  mPredictTextView = (AutoCompleteTextView) findViewById( R.id.txtSearch);
  mAdapter = new AutoCompleteAdapter( this );
  mPredictTextView.setAdapter( mAdapter );
  mPredictTextView.setOnItemClickListener( new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      AutoCompletePlace place = (AutoCompletePlace) parent.getItemAtPosition( position );
      findPlaceById( place.getId() );
    }
  });
  mGoogleApiClient = new GoogleApiClient
      .Builder( this )
      .enableAutoManage( this, 0, this )
      .addApi( Places.GEO_DATA_API )
      .addApi( Places.PLACE_DETECTION_API )
      .addConnectionCallbacks( this )
      .addOnConnectionFailedListener( this )
      .build();
}
@Override

代码示例来源:origin: zadr50/Gojek

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_place_find);
  mTextView = (TextView) findViewById( R.id.textview );
  mPredictTextView = (AutoCompleteTextView) findViewById( R.id.txtSearch);
  mAdapter = new AutoCompleteAdapter( this );
  mPredictTextView.setAdapter( mAdapter );
  mPredictTextView.setOnItemClickListener( new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      AutoCompletePlace place = (AutoCompletePlace) parent.getItemAtPosition( position );
      findPlaceById( place.getId() );
    }
  });
  mGoogleApiClient = new GoogleApiClient
      .Builder( this )
      .enableAutoManage( this, 0, this )
      .addApi( Places.GEO_DATA_API )
      .addApi( Places.PLACE_DETECTION_API )
      .addConnectionCallbacks( this )
      .addOnConnectionFailedListener( this )
      .build();
}
@Override

相关文章

AutoCompleteTextView类方法