Android Question Java query - use of ArrayAdapter in B4A?

agraham

Expert
Licensed User
Longtime User
I'm jumping straight into the deep end at outer extents of my knowledge of Android layouts (to mix a metaphor or two)!

Is it possible to use an ArrayAdapter with views in B4A? All the constructors seem to need ids from the R file produced by the layout XML which B4A doesn't do.
 

agraham

Expert
Licensed User
Longtime User
One of the limitations of my BasicIDE has always been the editor based on an EditText. Unbeknownst to me there is apparently an extension of EditText with more capability called MultiAutoCompleteTextView which is used by this very small library which I am wrapping.

So far I am very pleased to have syntax and error line highlighting working in BasicIDE which is giving a far better development experience, although my regexes are probably a bit primitive . The cherry on the cake would be to add autocomplete which is supported by the library.
Java:
Add Custom AutoComplete Adapter

//Your langauge keywords
String[] languageKeywords = .....
//List item custom layout
int layoutId = .....
//TextView id on your custom layout to put suggestion on it
int viewId = .....
//Create ArrayAdapter object that contain all information
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, layoutId, viewId, languageKeywords);
//Set the adapter on CodeView object
codeView.setAdapter(adapter);
However I am totally at a loss at how to create the ArrayAdapter as it requires a layout Id and a view Id that I really don't understand what they are the Ids of, except that they seem to come from the R file. It doesn't help that I don't really know what an ArrayAdaper does. :(
 

Attachments

  • CodeViewWrapper.java
    5.3 KB · Views: 126
  • CodeView.java
    13.2 KB · Views: 112
  • KeywordTokenizer.java
    980 bytes · Views: 105
Upvote 0

agraham

Expert
Licensed User
Longtime User
You can get the views id with:
That's good, the road ahead may not be blocked then. :) Any idea what views the layoutI and viewId should belong to in this case? A specially added Panel with a Label child? I'll go and play.
If you must use XML layouts
That's the last thing I ever want to do. My tiny semi-autistic mind can't cope with declarative stuff like Regex, Xml and Html, although I do try on occasion. Procedural logic is what I am best at.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Looks like its a Resource Id needed so I guess I'm stuck :(
android.content.res.Resources$NotFoundException: Resource ID #0xb
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:239)
at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:96)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
at android.content.res.Resources.getLayout(Resources.java:1189)
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:428)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:419)
at android.widget.AbsListView.obtainView(AbsListView.java:2437)
at android.widget.DropDownListView.obtainView(DropDownListView.java:305)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1441)
at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1299)
at android.widget.ListPopupWindow.originalShow(ListPopupWindow.java:651)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:645)
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1316)
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Searching the forum I guess CreateResource in the manifest editor might do what I want.
That I suppose will at least go into the R file. I'll play with that but I'm really running blind here :(
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Yes ? BasicIDE has a primitive looking autautocomplete working after a process of hitting it around the head with trial and error and ignorance until it succumbed! Needs tidying up to production standard now :(

I used CreateRsource in the manifest to get the layout into the resources and JavaObject to get the resource Ids which were needed, not the view Ids.
 
Upvote 0
Top