大佬教程收集整理的这篇文章主要介绍了android – 在uiautomator中从AutoCompleteTextView中选择项目,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您可以看到捕捉和视图[全部展开]. AutoCompleteTextView的下拉菜单不会出现在视图树中,也可以使用鼠标进行选择.
我已经尝试下列方法从AutoCompleteTextView适配器中选择项目表单:
> UiScrollable LOCATIOnList = new UiScrollable(new UiSELEctor().scrollable(true));
LOCATIOnList.scrollTexTintoView(位置);
> UiScrollable LOCATIOnList = new UiScrollable(LOCATIOnEditText.getSELEctor());
LOCATIOnList.scrollTexTintoView(位置);这里的LOCATIOnEditText是我的AutoCompleteTextView
> UiObject SELEctedLOCATIOn = LOCATIOnList.getChild(new UiSELEctor().text(LOCATIOn));
SELEctedLOCATIOn.click();从LOCATIOnList,它不会选择带有字符串的项目.
> editLOCATIOnResId =“android:id / text1”;
UiObject SELEctedLOCATIOn = new UiObject(new UiSELEctor().resourcEID(editLOCATIOnResId));
SELEctedLOCATIOn.click();来自adpter textview的id也不起作用.
任何人可以帮助我从uiautomator中的AutoCompleteTextView中选择项目?或者更多的方法得到欲望输出.
我使用AutoCompleteText来自动完成用户当前所在的位置,LOCATIOnList只不过是在Strings.xml文件中写的数组,所以在这里使用你自己的字符串数组.
LOCATIOnList = res.getStringArray(R.array.ticketLOCATIOn); ArrayAdapter<String> LOCATIOnAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,LOCATIOnList); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.txtCountries); textView.setThreshold(1); textView.setAdapter(LOCATIOnAdapter); textView.SETVALidator(new Validator()); textView.setOnFocuschangelistener(new FocusListener()); textView.setOnItemClickListener(new AdapterView.onItemClickListener() { @Override public void onItemClick(AdapterView<?> parent,View view,int position,long id) { // TODO Auto-generated method stub TextView ticketLOCATIOn = (TextView) view; getTicketLOCATIOn = ticketLOCATIOn.getText().toString(); } });
以下是用于验证位置字段中的文本输入的代码,fixText()方法阻止用户键入字符串数组中不存在的文本,例如:如果用户键入“geRMANy”,不存在您的字符串数组列表将被替换为“”,它是编辑文本输入字段中的空字符串
class Validator implements AutoCompleteTextView.Validator { @Override public Boolean isValid(CharSequence text) { // Log.v("Test","checking if valid: " + text); Arrays.sort(LOCATIOnList); if (Arrays.binarySearch(LOCATIOnList,text.toString()) > 0) { return true; } return false; } @Override public CharSequence fixText(CharSequence invalidText) { // Log.v("Test","Returning fixed text"); /* * I'm just returning an empty String here,so the field will be * blanked,but you Could put any kind of action here,like popping * up a dialog? * * whatever value you return here must be in the list of valid * words. */ return ""; } } class FocusListener implements View.onFocuschangelistener { @Override public void onFocusChange(View v,Boolean hasFocus) { // Log.v("Test","Focus changed"); if (v.getId() == R.id.txtCountries && !hasFocus) { // Log.v("Test","Performing validation"); ((AutoCompleteTextView) v).performValidation(); } } }
以上是大佬教程为你收集整理的android – 在uiautomator中从AutoCompleteTextView中选择项目全部内容,希望文章能够帮你解决android – 在uiautomator中从AutoCompleteTextView中选择项目所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。