AutoCompleteTextField not populating

16 views
Skip to first unread message

steve nganga

unread,
Apr 10, 2017, 9:56:46 AM4/10/17
to codenameone...@googlegroups.com
I am fetching data from the the database and can even print the data on the overridden filter method of the AutoCompleteTextField. The issue is that even after adding the newly fetched items in the DefaultListModel..  the items are not being displayed in the in the popup of the autoComplete. What could be the issu

Screenshot below

Inline image 1

Here is my Code.



import com.codename1.ui.AutoCompleteTextField;
import com.codename1.ui.list.DefaultListModel;

public class AutoCompleteUI extends AutoCompleteTextField {

    private DefaultListModel dlm;

    public AutoCompleteUI(DefaultListModel model) {
        this.dlm = model;
        setMinimumElementsShownInPopup(5);
    }

    @Override
    public boolean filter(String text) {
        if (text.trim().length() == 0) {
            return false;
        }
        
        try
        {
             String data[]=ConnectionUtil.getResultsFromDB(text);
             dlm.removeAll();
             
             if(data==null || data.length==0)
                 return false;
             
             for(String res:data)
             {
                 System.out.println(res);
                 dlm.addItem(res);
             }
             return true;
             
        }catch(Exception io)
        {
            io.printStackTrace();
        }
       

        return false;
    }

   
}

Where the Component is added
 DefaultListModel<String> dlm=new DefaultListModel<>();        
  AutoCompleteUI vp=new AutoCompleteUI(dlm);



Steve Hannah

unread,
Apr 10, 2017, 12:08:20 PM4/10/17
to codenameone...@googlegroups.com
You need to call super(model) in your constructor so that your model will be used.

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/CAOfyKqa%3DW1NRG8mOBdagxj2dcwPPYjfMCBH4spwwtFMyZrKV6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One
Reply all
Reply to author
Forward
0 new messages