问题描述
如何使用黑莓手机自动完成现场时获得所选项目的字符串。我现在能拿到选定的索引。我覆盖在AutoCompleteField类中的方法ONSELECT截至
解释自动完成类参考API JDE 5.0
code以下片段 -
AutoCompleteField autoCompleteField =新AutoCompleteField(filterList)
{
公共无效ONSELECT(对象选择,诠释SELECT_TRACKWHEEL_CLICK){
ListField _list = getListField();
如果(_list.getSelectedIndex()-1个){
Dialog.alert(您选择:+ _list.getSelectedIndex());
//获取用户选定的文本,做一些事情...
}
}
};
AutoCompleteField#ONSELECT(对象,INT)的默认实现将AutoCompleteField对象的AutoCompleteFieldEditField到选择参数的文本。所以,你可以查询字符串的方式。下面是我的意思的代码段:
AutoCompleteField autoCompleteField =新AutoCompleteField(filterList)
{
公共无效ONSELECT(对象选择,整型){
super.onSelect(选择型);
如果(选择!= NULL){
字符串selectionAsString = getEditField()的getText()。
//你需要用字符串做其他。
}
}
};
How to get the selected Item as string when using a Blackberry AutoComplete Field. I am able to get the selected index currently. I am Overriding the onSelect method in the AutoCompleteField class as explained at
Autocomplete Class Reference API JDE 5.0
Code Snippet below -
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList)
{
public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
ListField _list = getListField();
if (_list.getSelectedIndex() > -1) {
Dialog.alert("You selected: "+_list.getSelectedIndex());
// get text selected by user and do something...
}
}
};
The default implementation of AutoCompleteField#onSelect(Object, int) sets the text of the AutoCompleteField object's AutoCompleteFieldEditField to the select parameter. So you could query for the String that way. Here's a snippet of what I mean:
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList)
{
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if(selection != null) {
String selectionAsString = getEditField().getText();
// Do whatever else you need to do with the String.
}
}
};
这篇关于如何获得所选择的项目为String在黑莓AutoCompleteField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!