Android 中水平自动完成单词建议

发布于 2024-10-14 15:48:45 字数 1130 浏览 0 评论 0原文

我需要自动完成单词建议。当我在自动完成编辑文本框中单击“th”时,它将显示“the”,“there”,“those”...就像垂直列表视图上的那样。我需要显示它结果(那个,那里,那些..)以水平方式。我该怎么做?

我的代码是:

public class AutoCompleteDemo extends Activity
implements TextWatcher {
TextView selection;
AutoCompleteTextView edit;

String[] items={"lorem", "ipsum", "dolor", "sit", "amet",
"consectetuer", "adipiscing", "elit", "morbi", "vel",
"ligula", "vitae", "arcu", "aliquet", "mollis",
"etiam", "vel", "erat", "placerat", "ante",
"porttitor", "sodales", "pellentesque", "augue", "purus"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

edit=(AutoCompleteTextView)findViewById(R.id.edit);
edit.addTextChangedListener(this);
edit.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple dropdown item 1line,
items));
}


public void onTextChanged(CharSequence s, int start, int before,
int count) {

}


public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// needed for interface, but not used
}


public void afterTextChanged(Editable s) {
// needed for interface, but not used
}
}

i need to do auto complete word suggestion.When i click "th"on Autocomplete edit text box,It will display "the","there","those"...like that on vertical list view.I need to display that results(the,there,those..)on horizontal way.How could i do this?

My code is:

public class AutoCompleteDemo extends Activity
implements TextWatcher {
TextView selection;
AutoCompleteTextView edit;

String[] items={"lorem", "ipsum", "dolor", "sit", "amet",
"consectetuer", "adipiscing", "elit", "morbi", "vel",
"ligula", "vitae", "arcu", "aliquet", "mollis",
"etiam", "vel", "erat", "placerat", "ante",
"porttitor", "sodales", "pellentesque", "augue", "purus"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

edit=(AutoCompleteTextView)findViewById(R.id.edit);
edit.addTextChangedListener(this);
edit.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple dropdown item 1line,
items));
}


public void onTextChanged(CharSequence s, int start, int before,
int count) {

}


public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// needed for interface, but not used
}


public void afterTextChanged(Editable s) {
// needed for interface, but not used
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文