本文整理汇总了Java中android.widget.AutoCompleteTextView.setOnEditorActionListener方法的典型用法代码示例。如果您正苦于以下问题:Java AutoCompleteTextView.setOnEditorActionListener方法的具体用法?Java AutoCompleteTextView.setOnEditorActionListener怎么用?Java AutoCompleteTextView.setOnEditorActionListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.AutoCompleteTextView
的用法示例。
在下文中一共展示了AutoCompleteTextView.setOnEditorActionListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
editSummaryContainer = inflater.inflate(R.layout.fragment_preview_summary, container, false);
summaryText = (AutoCompleteTextView) editSummaryContainer.findViewById(R.id.edit_summary_edit);
// Explicitly enable standard dictionary autocompletion in the edit summary box
// We should be able to do this in the XML, but doing it there doesn't work. Thanks Android!
summaryText.setInputType(summaryText.getInputType() & (~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE));
// ...so that clicking the "Done" button on the keyboard will have the effect of
// clicking the "Next" button in the actionbar:
summaryText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if ((keyEvent != null
&& (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))
|| (actionId == EditorInfo.IME_ACTION_DONE)) {
parentActivity.clickNextButton();
}
return false;
}
});
return editSummaryContainer;
}
示例2: setup
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
private void setup() {
mSearchText = (AutoCompleteTextView) findViewById(R.id.etInput);
mSearchText.addTextChangedListener(this);
mSearchText.setHint(getString(R.string.search_map));
findViewById(R.id.search_back).setOnClickListener(view -> {
finish();
});
mSearchText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_SEARCH) {
doSearch();
}
return false;
});
}
示例3: 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;
}
});
}
示例4: onCreate
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
getTheme().applyStyle(SharedPrefs.getFontSize().getResId(), true);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
UtilFunctions.applyReadingMode();
languageCode = SharedPrefs.getString(Constants.PrefKeys.LAST_OPEN_LANGUAGE_CODE, "ENG");
versionCode = SharedPrefs.getString(Constants.PrefKeys.LAST_OPEN_VERSION_CODE, Constants.VersionCodes.ULB);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white);
toolbar.setContentInsetStartWithNavigation(0);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.auto_complete_search);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
noResultsFound = (LinearLayout) findViewById(R.id.no_results_found);
mIvClose = (ImageView) findViewById(R.id.iv_close);
mRecyclerView = (RecyclerView) findViewById(R.id.list_results);
sectionGroupView = (RadioGroup) findViewById(R.id.section_group);
numOfResults = (TextView) findViewById(R.id.numResults);
sectionGroupView.setOnCheckedChangeListener(this);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new SearchAdapter(this, mShowSearchResultModels);
mRecyclerView.setAdapter(mAdapter);
mIvClose.setOnClickListener(this);
mAutoCompleteTextView.setOnClickListener(this);
mAutoCompleteTextView.setOnEditorActionListener(this);
}
示例5: 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);
}
示例6: showAddFilterDialog
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
private void showAddFilterDialog(final FilterAdapter filterAdapter) {
// show a popup to add a new filter text
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams")
final AutoCompleteTextView editText =
(AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false);
// show suggestions as the user types
List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet);
SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>(
this, R.layout.list_item_dropdown, suggestions);
editText.setAdapter(suggestionAdapter);
final MaterialDialog alertDialog = new MaterialDialog.Builder(this)
.title(R.string.add_filter)
.positiveText(android.R.string.ok)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
handleNewFilterText(editText.getText().toString(), filterAdapter);
dialog.dismiss();
}
})
.negativeText(android.R.string.cancel)
.customView(editText, true)
.build();
// when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// dismiss soft keyboard
handleNewFilterText(editText.getText().toString(), filterAdapter);
alertDialog.dismiss();
return true;
}
return false;
}
});
alertDialog.show();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);
}