本文整理汇总了Java中android.widget.AutoCompleteTextView.setOnItemClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java AutoCompleteTextView.setOnItemClickListener方法的具体用法?Java AutoCompleteTextView.setOnItemClickListener怎么用?Java AutoCompleteTextView.setOnItemClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.AutoCompleteTextView
的用法示例。
在下文中一共展示了AutoCompleteTextView.setOnItemClickListener方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeSearchSuggestions
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
/**
* method to generate search suggestions for the AutoCompleteTextView from
* previously searched URLs
*/
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
getUrl.setThreshold(1);
getUrl.setDropDownWidth(-1);
getUrl.setDropDownAnchor(R.id.toolbar_layout);
getUrl.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
});
getUrl.setSelectAllOnFocus(true);
mSearchAdapter = new SearchAdapter(mActivity, mDarkTheme, isIncognito());
getUrl.setAdapter(mSearchAdapter);
}
示例2: PlaceAutoCompleteHelper
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
public PlaceAutoCompleteHelper(AutoCompleteTextView ... act, FragmentActivity fa) {
Context ctx = act[0].getContext();
mGoogleApiClient = new GoogleApiClient.Builder(ctx)
.enableAutoManage(fa, 0, this)
.addApi(Places.GEO_DATA_API)
.addApi(LocationServices.API)
.build();
mAdapter = new PlaceAutoCompleteAdapter(ctx, mGoogleApiClient,
null);
for (AutoCompleteTextView ac:act) {
ac.setOnItemClickListener(mAutocompleteClickListener);
ac.setAdapter(mAdapter);
ac.setOnFocusChangeListener(this);
}
placeIcon = act[0].getContext().getResources().getDrawable(R.drawable.ic_map_marker);
}
示例3: onCreate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
.addApi(Places.GEO_DATA_API)
.enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
.addConnectionCallbacks(this)
.build();
mAutocompleteTextView = (AutoCompleteTextView) findViewById(R.id
.autoCompleteTextView);
mAutocompleteTextView.setThreshold(3);
mNameTextView = (TextView) findViewById(R.id.name);
mAddressTextView = (TextView) findViewById(R.id.address);
mIdTextView = (TextView) findViewById(R.id.place_id);
mPhoneTextView = (TextView) findViewById(R.id.phone);
mWebTextView = (TextView) findViewById(R.id.web);
mAttTextView = (TextView) findViewById(R.id.att);
mAutocompleteTextView.setOnItemClickListener(mAutocompleteClickListener);
mPlaceArrayAdapter = new PlaceArrayAdapter(this, android.R.layout.simple_list_item_1,
BOUNDS_MOUNTAIN_VIEW, null);
mAutocompleteTextView.setAdapter(mPlaceArrayAdapter);
}
示例4: createNewTextView
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
private AutoCompleteTextView createNewTextView(final EditText et) {
final TableRow.LayoutParams lparams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
final AutoCompleteTextView textView = new AutoCompleteTextView(this.getContext());
lparams.weight = 10;
textView.setHint(R.string.add_ingredient);
textView.setLayoutParams(lparams);
textView.setAdapter(adapter);
textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Ingredient ingr = (Ingredient) adapterView.getAdapter().getItem(i);
ViewGroup vg= (ViewGroup) textView.getParent();
setETsForUnits(ingr.getMeasureUnit(),ingr.getMeasureValue(),ingr.getDefaultUnit(),ingr.getDefaultValue(),vg);
}
});
return textView;
}
示例5: init_placeAPI
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
private void init_placeAPI() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Places.GEO_DATA_API)
.enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
.addConnectionCallbacks(this)
.build();
addLocation = (AutoCompleteTextView) findViewById(R.id
.addLocation);
addLocation.setThreshold(3);
addLocation.setOnItemClickListener(mAutocompleteClickListener);
mPlaceArrayAdapter = new PlaceAdapter(this, android.R.layout.simple_list_item_1,
BOUNDS_MOUNTAIN_VIEW, null);
addLocation.setAdapter(mPlaceArrayAdapter);
}
示例6: onCreateOptionsMenu
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_search, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView =
(SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(this);
searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false);
if (isInputMode) {
MenuItemCompat.expandActionView(searchItem);
} else {
MenuItemCompat.collapseActionView(searchItem);
}
MenuItemCompat.setOnActionExpandListener(searchItem, this);
AutoCompleteTextView autoCompleteTextView = searchView
.findViewById(android.support.v7.appcompat.R.id.search_src_text);
autoCompleteTextView.setThreshold(0);
autoCompleteTextView.setAdapter(new ArrayAdapter<>(this,
R.layout.layout_item_simple_list, mPresenter.getSearchRecordList()));
autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity())));
autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> {
onQueryTextSubmit(parent.getAdapter().getItem(position).toString());
});
return super.onCreateOptionsMenu(menu);
}
示例7: initializeSearchSuggestions
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
/**
* method to generate search suggestions for the AutoCompleteTextView from
* previously searched URLs
*/
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
mSuggestionsAdapter = new SuggestionsAdapter(this, mDarkTheme, isIncognito());
getUrl.setThreshold(1);
getUrl.setDropDownWidth(-1);
getUrl.setDropDownAnchor(R.id.toolbar_layout);
getUrl.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
String url = null;
CharSequence urlString = ((TextView) view.findViewById(R.id.url)).getText();
if (urlString != null) {
url = urlString.toString();
}
if (url == null || url.startsWith(getString(R.string.suggestion))) {
CharSequence searchString = ((TextView) view.findViewById(R.id.title)).getText();
if (searchString != null) {
url = searchString.toString();
}
}
if (url == null) {
return;
}
getUrl.setText(url);
searchTheWeb(url);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
mPresenter.onAutoCompleteItemPressed();
}
});
getUrl.setSelectAllOnFocus(true);
getUrl.setAdapter(mSuggestionsAdapter);
}
示例8: generate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
/**
* @param editField The component to "transform" into one that shows a city drop down list
* based on the current input. Make sure to pass an initialized object,
* else a java.lang.NullPointerException will be thrown.
* @param listLimit Determines how many items shall be shown in the drop down list at most.
*/
public void generate(AutoCompleteTextView editField, int listLimit, final int enterActionId, final MyConsumer<City> cityConsumer, final Runnable selectAction) {
cityAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new ArrayList<City>());
this.editField = editField;
this.cityConsumer = cityConsumer;
this.listLimit = listLimit;
editField.setAdapter(cityAdapter);
editField.addTextChangedListener(new TextChangeListener());
editField.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedCity = (City) parent.getItemAtPosition(position);
cityConsumer.accept(selectedCity);
}
});
editField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == enterActionId) {
Boolean checkCity = checkCity();
if (checkCity) {
selectAction.run();
}
return true;
}
return false;
}
});
}
示例9: initializeSearchSuggestions
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
/**
* method to generate search suggestions for the AutoCompleteTextView from
* previously searched URLs
*/
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
getUrl.setThreshold(1);
getUrl.setDropDownWidth(-1);
getUrl.setDropDownAnchor(R.id.toolbar_layout);
getUrl.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
try {
String url;
url = ((TextView) arg1.findViewById(R.id.url)).getText().toString();
if (url.startsWith(BrowserActivity.this.getString(R.string.suggestion))) {
url = ((TextView) arg1.findViewById(R.id.title)).getText().toString();
} else {
getUrl.setText(url);
}
searchTheWeb(url);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
if (mCurrentView != null) {
mCurrentView.requestFocus();
}
} catch (NullPointerException e) {
Log.e("Browser Error: ", "NullPointerException on item click");
}
}
});
getUrl.setSelectAllOnFocus(true);
mSearchAdapter = new SearchAdapter(this, mDarkTheme, isIncognito());
getUrl.setAdapter(mSearchAdapter);
}
示例10: initializeSearchSuggestions
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
/**
* method to generate search suggestions for the AutoCompleteTextView from
* previously searched URLs
*/
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
getUrl.setThreshold(1);
getUrl.setDropDownWidth(-1);
getUrl.setDropDownAnchor(R.id.toolbar_layout);
getUrl.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
try {
String url;
url = ((TextView) arg1.findViewById(R.id.url)).getText().toString();
if (url.startsWith(BrowserActivityInc.this.getString(R.string.suggestion))) {
url = ((TextView) arg1.findViewById(R.id.title)).getText().toString();
} else {
getUrl.setText(url);
}
searchTheWeb(url);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
if (mCurrentView != null) {
mCurrentView.requestFocus();
}
} catch (NullPointerException e) {
Log.e("Browser Error: ", "NullPointerException on item click");
}
}
});
getUrl.setSelectAllOnFocus(true);
mSearchAdapter = new SearchAdapter(this, mDarkTheme, isIncognito());
getUrl.setAdapter(mSearchAdapter);
}
示例11: onCreate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.manPages = initPages();
ArrayAdapter<Page> manPagesAdapter = new ArrayAdapter<Page>(this,
android.R.layout.simple_list_item_1, manPages);
ArrayAdapter<Page> manPagesCompleteAdapter = new ArrayAdapter<Page>(
this, android.R.layout.simple_dropdown_item_1line, manPages);
// Main list of all manpages
ListView manPagesView = (ListView) findViewById(R.id.pages_names);
manPagesView.setAdapter(manPagesAdapter);
manPagesView.setOnItemClickListener(new OnManpageClickListener(this));
// List of manpages displayed in the text field suggestions
AutoCompleteTextView manPagesCompleteTextView = (AutoCompleteTextView) findViewById(R.id.search_input);
manPagesCompleteTextView.setAdapter(manPagesCompleteAdapter);
manPagesCompleteTextView
.setOnItemClickListener(new OnManpageClickListener(this));
// Check the availability of files on external storage
if (!checkPageFilesOnExternalStorage(null))
suggestDownload();
// Handle the Enter key in the TextView
// Get the input TextView
AutoCompleteTextView input = (AutoCompleteTextView) findViewById(R.id.search_input);
// Create a new handler for the Enter key ("Go" key here)
TextView.OnEditorActionListener enterKeyListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
// If search key was hit, search for this manpage
if (actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_NULL) {
Page p = getManpageCalled(v.getText().toString());
if (p != null) {
// display it if found,
displayManpage(p);
} else {
// else display an error message
Toast.makeText(getApplicationContext(),
"This manpage does not exist...",
Toast.LENGTH_LONG).show();
}
}
return true;
}
};
input.setOnEditorActionListener(enterKeyListener);
}
示例12: onCreate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_place_on_map);
getSupportActionBar().setTitle("Search Places");
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
fabAdd= (FloatingActionButton) findViewById(R.id.fab_add);
fabAdd.setOnClickListener(this);
mAutocompleteView = (AutoCompleteTextView)
findViewById(R.id.googleplacesearch);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, 0 /* clientId */, this)
.addApi(Places.GEO_DATA_API)
.build();
mAdapter = new PlaceAutocompleteAdapter(this, R.layout.google_places_search_items,
mGoogleApiClient, null, null);
//TODO:In order to Restrict search to India uncomment this and comment the above line
/*
mAdapter = new PlaceAutocompleteAdapter(this, R.layout.google_places_search_items,
mGoogleApiClient, BOUNDS_GREATER_INDIA, null);
*/
mAutocompleteView.setAdapter(mAdapter);
mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener);
mAutocompleteView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (mAutocompleteView.getRight() - mAutocompleteView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
mAutocompleteView.setText("");
return true;
}
}
if (event.getRawX() <= (mAutocompleteView.getCompoundDrawables()[DRAWABLE_LEFT].getBounds().width())) {
Intent i = new Intent(SearchPlaceOnMapActivity.this, MainActivity.class);
startActivity(i);
finish();
return true;
}
return false;
}
});
}
示例13: onCreate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_item_shopping_list);
try {
shoppingList = ShoppingListDAO.select(this, getIntent().getExtras().getInt((getString(R.string.id_shopping_list))));
} catch (VansException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
this.setTitle(shoppingList.getName());
lvItensShoppingList = (ListView) findViewById(R.id.lvItemShoppingList);
lvItensShoppingList.setOnItemClickListener(this);
lvItensShoppingList.setOnItemLongClickListener(this);
headerView = (View) getLayoutInflater().inflate(R.layout.header_list_view_item_shopping_list, null);
lvItensShoppingList.addHeaderView(headerView, null, false);
adapter = new ItemShoppingListCursorAdapter(this, shoppingList.getId());
lvItensShoppingList.setAdapter(adapter);
edUnitValue = (EditText) findViewById(R.id.edUnitValue);
edUnitValue.setVisibility(UserPreferences.getShowUnitValue(this) ? View.VISIBLE : View.GONE);
edUnitValue.setOnKeyListener(this);
edUnitValue.addTextChangedListener(new CustomEditTextWatcher(edUnitValue, 5));
edUnitValue.setOnFocusChangeListener(this);
edQuantity = (EditText) findViewById(R.id.edQuantity);
edQuantity.addTextChangedListener(new CustomEditTextWatcher(edQuantity, 4));
edQuantity.setVisibility(UserPreferences.getShowQuantity(this) ? View.VISIBLE : View.GONE);
edQuantity.setOnFocusChangeListener(this);
edDescription = (AutoCompleteTextView) findViewById(R.id.edDescription);
edDescription.setOnItemClickListener(this);
edDescription.addTextChangedListener(new CustomEditTextWatcher(edDescription, -1));
if ((!UserPreferences.getShowQuantity(this)) && (!UserPreferences.getShowUnitValue(this))) {
edDescription.setImeOptions(EditorInfo.IME_ACTION_GO);
edDescription.setOnKeyListener(this);
} else if (!UserPreferences.getShowUnitValue(this)) {
edQuantity.setImeOptions(EditorInfo.IME_ACTION_GO);
edQuantity.setOnKeyListener(this);
}
}
示例14: onCreate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_location2);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
try {
setUpMapIfNeeded();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(new Criteria(), false);
Location location = locationManager.getLastKnownLocation(provider);
if(location != null) {
onLocationChanged(location);
}
mGoogleApiClient = buildApiClient();
mGoogleApiClient.connect();
mAdapter = new PlaceAutocompleteAdapter (getApplicationContext(), mGoogleApiClient, null,
null);
mSearchLocation = (AutoCompleteTextView) findViewById(R.id.searchLocation);
mSearchLocation.setAdapter(mAdapter);
mSearchLocation.setOnItemClickListener(mAutocompleteClickListener);
}catch (Exception e){
e.printStackTrace();
}
}