Java Question Why no code completion?

warwound

Expert
Licensed User
Longtime User
I'm working on a library and for some reason the B4A IDE code completion fails to appear...

I can manually enter the code and the B4A project compiles and runs ok.

I can invoke code completion to add a Sub for the library's only event.
And after typing a method name the code completion shows the parameter names and types that that method accepts.

But the method names and properties themselves do not appear.

This code compiles and works as expected:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim ImageButtonsView1 As ImageButtonsView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   ImageButtonsView1.Initialize("ImageButtonsView1")
   ImageButtonsView1.AddButtons(Array As String("previous", "center", "next"))
   
   Activity.AddView(ImageButtonsView1, 0, 5, -2, -2)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ImageButtonsView1_Click(DrawableId As String)
   Log(DrawableId)
   Select DrawableId
      Case "previous"
         ImageButtonsView1.Orientation=ImageButtonsView1.VERTICAL
      Case "next"
         ImageButtonsView1.Orientation=ImageButtonsView1.HORIZONTAL
   End Select
End Sub

Type ImageButtonsView1. and no code completion appears.

Type ImageButtonsView1.AddButtons( and as soon as you type the ( the parameter help appears.

Here's the library wrapper class:

B4X:
package uk.co.martinpearman.b4a.imagebuttonsview;

import android.util.Log;
import android.widget.LinearLayout;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ActivityObject
@Author("Martin Pearman")
@Events(values = { "Click(DrawableId As String)"})
@ShortName("ImageButtonsView")
@Version(1.00f)
public class ImageButtonsViewWrapper extends AbsObjectWrapper<ImageButtonsView> {
   final public static int HORIZONTAL=LinearLayout.HORIZONTAL;
   final public static int VERTICAL=LinearLayout.VERTICAL;
   
   /**
    * DrawableIds is an Array of Strings.
    *Each String is the identifier of an application resource Drawable.
    */
   public void AddButtons(String[] DrawableIds){
      getObject().addButtons(DrawableIds);
   }
   
   public void getButtonVisible(){
      
   }
   
   public void getOrientation(){
      
   }
   
   public void Initialize(BA pBA, String EventName){
      if(pBA.subExists(EventName.toLowerCase()+"_click")){
         setObject(new ImageButtonsView(pBA, EventName));
      } else {
         Log.e("B4A", "Failed to Initialize ImageButtonView Sub '"+EventName+"_Click' not found");
      }
   }
   
   public void setButtonVisible(){
      
   }
   
   /**
    * Default orientation is LinearLayout.HORIZONTAL
    */
   public void setOrientation(int Orientation){
      getObject().setOrientation(Orientation);
   }
}

And the non-wrapper class:

B4X:
package uk.co.martinpearman.b4a.imagebuttonsview;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Hide;

@Hide
public class ImageButtonsView extends LinearLayout implements OnClickListener{
   private BA mBA;
   private String mEventName;
   private ImageButton[] mImageButton;
   
   public ImageButtonsView(BA pBA, String pEventName) {
      super(pBA.context);
      mBA=pBA;
      mEventName=pEventName.toLowerCase()+"_click";
   }
   
   public void addButtons(String[] pDrawableId){
      mImageButton=new ImageButton[pDrawableId.length];
      for(int i=0; i<pDrawableId.length; i++){
         mImageButton[i]=new ImageButton(mBA.context);
         mImageButton[i].setImageDrawable(BA.applicationContext.getResources().getDrawable(
               BA.applicationContext.getResources().getIdentifier(pDrawableId[i], "drawable", BA.packageName)));
         mImageButton[i].setTag(pDrawableId[i]);
         mImageButton[i].setOnClickListener(this);
         addView(mImageButton[i], new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
      }
   }

   @Override
   public void onClick(View pView) {
      mBA.raiseEvent(ImageButtonsView.this, mEventName, new Object[]{(String) pView.getTag()});
   }
}

I've refreshed the B4A IDE libraries window, restarted B4A a few times, restarted Eclipse a couple of times and even rebooted my PC and tried again but still no code completion.

I can open the library's XML file with Firefox and it contains the references to the public methods:

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <doclet-version-NOT-library-version>1.02</doclet-version-NOT-library-version>
    <class>
        <name>uk.co.martinpearman.b4a.imagebuttonsview.ImageButtonsViewWrapper</name>
        <shortname>ImageButtonsView</shortname>
        <objectwrapper>uk.co.martinpearman.b4a.imagebuttonsview.ImageButtonsView</objectwrapper>
        <owner>process</owner>
        <event>Click(DrawableId As String)</event>
        <method>
            <name>Initialize</name>
            <comment></comment>
            <returntype>void</returntype>
            <parameter>
                <name>pBA</name>
                <type>anywheresoftware.b4a.BA</type>
            </parameter>
            <parameter>
                <name>EventName</name>
                <type>java.lang.String</type>
            </parameter>
        </method>
        <method>
            <name>setButtonVisible</name>
            <comment></comment>
            <returntype>void</returntype>
        </method>
        <method>
            <name>AddButtons</name>
            <comment>DrawableIds is an Array of Strings.
Each String is the identifier of an application resource Drawable.</comment>
            <returntype>void</returntype>
            <parameter>
                <name>DrawableIds</name>
                <type>java.lang.String[]</type>
            </parameter>
        </method>
        <method>
            <name>IsInitialized</name>
            <comment></comment>
            <returntype>boolean</returntype>
        </method>
        <property>
            <name>ButtonVisible</name>
            <returntype>void</returntype>
            <comment></comment>
        </property>
        <property>
            <name>Orientation</name>
            <returntype>void</returntype>
            <parameter>
                <name>Orientation</name>
                <type>int</type>
            </parameter>
            <comment>Default orientation is LinearLayout.HORIZONTAL</comment>
        </property>
        <field>
            <name>HORIZONTAL</name>
            <comment></comment>
            <returntype>int</returntype>
        </field>
        <field>
            <name>VERTICAL</name>
            <comment></comment>
            <returntype>int</returntype>
        </field>
    </class>
    <version>1.0</version>
    <author>Martin Pearman</author>
</root>


Can anyone see what i'm doing wrong?

The project is attached.

Thanks.

Martin.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It seems to work fine here:
SS-2012-04-22_15.42.35.png


Maybe you have a conflict with a similar library?
 

warwound

Expert
Licensed User
Longtime User
But your screengrab show code completion for my TouchImageView library not this ImageButtonsView library...

Have i been working too hard and messed everything up - i deleted my TouchImageView jar and xml and tried again bit it's the same.

Martin.
 
Top