我有两个类autoCompleteTextfiled.java和BillingController.java。
AutocompleteTextFilled是一个自定义类。当我选择一个弹出窗口时,我得到了结果。
代码如下:
private void populatePopup(List<String> searchResult) {
List<CustomMenuItem> menuItems = new LinkedList<>();
// If you'd like more entries, modify this line.
int maxEntries = 10;
int count = Math.min(searchResult.size(), maxEntries);
for (int i = 0; i < count; i++)
{
final String result = searchResult.get(i);
Label entryLabel = new Label(result);
CustomMenuItem item = new CustomMenuItem(entryLabel, true);
item.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent actionEvent) {
setText(result);
selectedTextFromMenu(result);
entriesPopup.hide();
}
});
menuItems.add(item);
}
entriesPopup.getItems().clear();
entriesPopup.getItems().addAll(menuItems);
}
private void selectedTextFromMenu(String result) {
AutoCompleteTextField autoCompleteTextField = new AutoCompleteTextField();
ItemSelectedListener mListener = new BillingController();
autoCompleteTextField.registerOnGeekEventListener(mListener);
autoCompleteTextField.selectItemListener(result);
}
public interface ItemSelectedListener
{
void getSelectedResult(String result);
}
public void registerOnGeekEventListener(ItemSelectedListener mListener)
{
this.itemSelectedListener = mListener;
}
public void selectItemListener(String result)
{
if (this.itemSelectedListener != null) {
itemSelectedListener.getSelectedResult(result);
}
}
但我尝试从BillingControllerClass访问AutoCompleteTextFiled的结果返回null。
@Override
public void getSelectedResult(String result) {
System.out.println("The pin has been changed>"+billingItemDetails.size());//billingItemDetails retunes 0
for (int j= 0; j<billingItemDetails.size();j++)
{
ItemListRequestAndResponseModel.item_list item_list = billingItemDetails.get(j);
if (item_list.getItem_name().equals(result))
{
System.out.println("The pin has been changed---->"+result);
txtFieldId.setText(item_list.getShort_code());//Textfiledis retunes null
}
}
}
}
但billingItemDetails(Arraylist)返回0.但最初ArrayList有一个数据。
请帮助我。