Java Question AutoCompleteEditText Force Full List to show

Roger Garstang

Well-Known Member
Licensed User
Longtime User
How do I go about doing this either with Android View or with the B4A version when there is text in the view that causes the list to be filtered when shown (This behavior seems odd too since it should only filter when typing, not when showing the list by code).

Best and most simple answer I've seen is calling performFiltering("", 0) which would filter it to be all values and show the list. Unfortunately I see it in the documents, but not in Eclipse (Looks like it is Protected, so can B4A even call it since it is just wrapping the view?). 2nd best answer was setting the text of the view to "" then showing the dropdown list, but this seems like a hack (plus I have to restore the text and the filtering sounds like it is done Asynchronous which may give problems).
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Nope, that still shows a filtered list. Apparently there is a hidden function that has been around a while, but just recently unhidden in newest API levels that turns off Filtering when Setting Text of the view with a boolean value in SetText. I guess I'll try to Extend the Autocomplete view and add a method to call performFiltering and see how it goes since trying to use the alternate SetText would limit the Android Version I can use.

I also noticed something weird with the text I set with setCompletionHint. When testing it in a small app it usually always appeared except when the list was filtered down to nothing. Using it in a larger app now with a full screen of controls it never appears??? I'm going to have to experiment with setting Dropdown height to see if I can get that back now too.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Ok, I'm really close on this, but it is driving me nuts as to why it isn't working. So, I made a Class called AutoCompleteEX which extends AutoCompleteTextView.

Within this class I have a method I added to show the full list:

B4X:
public void ShowFullList() {
   getFilter().filter(null);
   showDropDown();
}

Now, getting this to work with B4A has been an all day ordeal for some reason. Closest I got so far is below, but it seems to have lost the B4A events. The Autocomplete Edit Text was working pretty slick because it had the B4A ItemClicked event already, and my ShowFullList() call is working when clicked (The onClick worked before too with just showing the dropdown, although filtered, and B4A ItemClicked worked too). I've tried other ways including a ViewWrapper, Extending AutoCompleteEditTextWrapper to use AutoCompleteEX and various other ways, but I either get Class exceptions or missing events. What is the proper way/order to set the object and Initialize so Events are kept?

B4X:
public AutoCompleteEditTextWrapper AddCombobox(String ViewName, final String EventPrefix, int DataType, int ActionBtn, String Prompt, String Hint, int HintColor, float TextSize, int TextColor, List Items, Boolean ReadOnly, int BackgroundResourceID, final String NextView, final String PrevView){
   int BackgroundID= android.R.drawable.btn_dropdown;
   if (BackgroundResourceID != 0) BackgroundID= BackgroundResourceID;
   AutoCompleteEditTextWrapper b4aView= new AutoCompleteEditTextWrapper();
   AutoCompleteEX NewView= new AutoCompleteEX(ba.context);
   b4aView.setObject(NewView);
   b4aView.innerInitialize(ba, EventPrefix, true);
   
   NewView.setBackgroundResource(BackgroundID);
   NewView.setHint(Hint);
   NewView.setHintTextColor(HintColor);
   NewView.setCompletionHint(Prompt);
   NewView.setThreshold(1);
   NewView.setTextSize(TextSize);
   NewView.setTypeface(Typeface.DEFAULT);
   NewView.setTextColor(TextColor);
   NewView.setSingleLine(true);
   NewView.setHorizontallyScrolling(true);
   NewView.setScrollbarFadingEnabled(true);
   NewView.setEllipsize(TextUtils.TruncateAt.END);
   if (ReadOnly) {
      NewView.setFocusable(false);
      NewView.setInputType(0);
      NewView.setCursorVisible(false);
   }
   else {
      NewView.setInputType(DataType);
      NewView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | ActionBtn);
      
      NewView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

         @Override
         public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
               if (NextView.length() > 0) {
                  if (viewList.containsKey(NextView)) return viewList.get(NextView).requestFocus();
               }
               return false;
            }
            if (actionId == EditorInfo.IME_ACTION_PREVIOUS) {
               if (PrevView.length() > 0) {
                  if (viewList.containsKey(PrevView)) return viewList.get(PrevView).requestFocus();
               }
               return false;
            }
            if (EventPrefix.length() > 0) {
               Boolean b =  (Boolean)ba.raiseEvent(v, EventPrefix.toLowerCase(BA.cul) + "_imeaction");
               if (b != null && b == true)
                  return true;
               else
                  return false;
            }
            else {
               return false;
            }
         }                
      });
   }
   
   NewView.setOnClickListener(new OnClickListener() {
      
      @Override
      public void onClick(View MyView) {
         ((AutoCompleteEX) MyView).ShowFullList();
      }
   });
   
   if (Items.IsInitialized()) b4aView.SetItems(ba, Items);

   AddView(NewView, ViewName);
   return b4aView;
}
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…