本文整理汇总了Java中android.widget.AutoCompleteTextView.setOnTouchListener方法的典型用法代码示例。如果您正苦于以下问题:Java AutoCompleteTextView.setOnTouchListener方法的具体用法?Java AutoCompleteTextView.setOnTouchListener怎么用?Java AutoCompleteTextView.setOnTouchListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.AutoCompleteTextView
的用法示例。
在下文中一共展示了AutoCompleteTextView.setOnTouchListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupEditTagDialog
import android.widget.AutoCompleteTextView; //导入方法依赖的package包/类
private void setupEditTagDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PopupActivity.this);
LayoutInflater inflater = PopupActivity.this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_edit_tag, null);
dialogBuilder.setView(dialogView);
final AutoCompleteTextView editTag = (AutoCompleteTextView) dialogView.findViewById(R.id.edit_tag);
final CheckBox checkBoxSetAsDefaultTag = (CheckBox) dialogView.findViewById(R.id.checkbox_as_default_tag);
editTag.setImeOptions(EditorInfo.IME_ACTION_DONE);
if (mTagEditedByUser.size() == 1) {
String text = (String) mTagEditedByUser.toArray()[0];
editTag.setText(text);
editTag.setSelection(text.length());
}
List<UserTag> userTags = DataSupport.findAll(UserTag.class);
String[] arr = new String[userTags.size()];
for (int i = 0; i < userTags.size(); i++) {
arr[i] = userTags.get(i).getTag();
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PopupActivity.this,
R.layout.support_simple_spinner_dropdown_item, arr);
editTag.setAdapter(arrayAdapter);
editTag.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (editTag.getText().toString().isEmpty()) {
editTag.showDropDown();
}
return false;
}
});
boolean setDefaultQ = settings.getSetAsDefaultTag();
checkBoxSetAsDefaultTag.setChecked(setDefaultQ);
dialogBuilder.setTitle(R.string.dialog_tag);
//dialogBuilder.setMessage("输入笔记");
dialogBuilder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String tag = editTag.getText().toString().trim();
if (tag.isEmpty()) {
if (checkBoxSetAsDefaultTag.isChecked()) {
mTagEditedByUser.clear();
Toast.makeText(PopupActivity.this, R.string.tag_cant_be_blank, Toast.LENGTH_LONG).show();
} else {
settings.setSetAsDefaultTag(false);
mTagEditedByUser.clear();
}
return;
} else {
mTagEditedByUser.clear();
mTagEditedByUser.add(tag);
settings.setSetAsDefaultTag(checkBoxSetAsDefaultTag.isChecked());
settings.setDefaultTag(tag);
UserTag userTag = new UserTag(tag);
userTag.save();
}
}
});
AlertDialog b = dialogBuilder.create();
b.show();
}
示例2: 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;
}
});
}