用户使用editText时提供建议 [英] Offering suggestions whenever user uses editText

查看:83
本文介绍了用户使用editText时提供建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好朋友,



我正在构建一个Android应用程序,其中我的目标是向用户提供我的应用程序的建议

<每当他使用editText在任何应用程序中输入内容时,都会发出
文本。



这可能吗?如果我的应用程序作为服务运行,或者还有其他方式。



感谢您提前的帮助!!

解决方案
确定。你需要什么称为自动完成文本。这是基于输入的前几个字母向用户建议的文本,其中考虑了您包含的可能建议或先前输入的文本。



  public   class  CountriesActivity  extends 活动{
protected void onCreate(Bundle icicle){
.onCreate(冰柱);
setContentView(R.layout.countries);

ArrayAdapter< string> adapter = new ArrayAdapter< string>( this
android.R.layout.simple_dropdown_item_1line,国家);
AutoCompleteTextView textView =(AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}

private static final String [] COUNTRIES = new 字符串 [] {
option1 option2 bla bla bla etc。 选择了我
};
}< / string>< / string>


Hello freinds,

I am building an android app, in which i am aiming to give user suggestions of my application

text whenever he uses editText to enter something in any application.

Is this possible? If my app runs as a service, or is there some other way.

Thanks for your help in advance!!

解决方案

Sure. What you need is called AutoComplete text. This is text suggested to the user based on the first few letters typed, which takes into consideration possible suggestions you include, or previous text typed.

public class CountriesActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.countries);

         ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter);
     }

     private static final String[] COUNTRIES = new String[] {
         "option1", "option2", "bla bla bla", "etc.", "chose me"
     };
 }</string></string>


这篇关于用户使用editText时提供建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆