Java Question Library time again

barx

Well-Known Member
Licensed User
Longtime User
Hi chaps,

It's that time of year again, Barx tries his hand at a library. I really thought this one would be easy but I have fell at the first hurdle. I wish to make a Context Menu library ContextMenu | Android Developers
And following the usage example Android: Context menu example (on long press, gridview) | Stealthcopter.com

I created a pretty standard header for a lib.

B4X:
package barxdroid.contextmenu;

import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Version;

import android.view.ContextMenu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;

@ActivityObject
@ShortName("ContextMenu")
@Author("Barx")
@Version(1F)
@Events(values={"Click(ID as INT)"})

I'm guessing as this has to do with UI stuff I need the @ActivityObject?

OK the first instruction in the example is
B4X:
registerForContextMenu(btn);

I tried this 'as is' replacing btn for a view passed in the Initialize method. that create an error. I think i managed to get that bit sorted with

B4X:
ba.activity.registerForContextMenu(RegisterView);

The next step is to override the onCreateContextMenu. This is where I am stuck, I know I didn't get far lol. but i'm trying.

Any pointers?

Tried this but gives error

B4X:
         @Override
         public void onCreateContextMenu(Menu menu, View v, ContextMenuInfo menuinfo) {
            
         }

Also I set my class to extend AbsObjectWrapper like this

B4X:
public class contextmenu extends AbsObjectWrapper<ContextMenu>{
No idea if this is the right thing to do.

Been a long time since I messed with libs :signOops:

Any pointers would be great thanks.
 

barx

Well-Known Member
Licensed User
Longtime User
1) I didn't know your solution existed - I even asked you other night for a solution and you didn't mention this lol.

2) I want to get into the swing of creating libraries and thought of doing a couple of easy one to warm me up. Turned out not so easy lol.
 

barx

Well-Known Member
Licensed User
Longtime User
No worries dude, was debating using the input list but didn't want to view the radio buttons, so I guess your solution will work fine.

I would still like to know how to go about sorting this library though if anybody has any idea. thanks
 

barx

Well-Known Member
Licensed User
Longtime User
ha ha I think I posted that Radio post in the wrong thread, Had 2 active threads open It was meant to go in the other one which is about my current phone issues.

Erel if you could move that post and walters reply to this thread

http://www.b4x.com/forum/chit-chat/26303-non-b4a-phone-loosing-network.html

then delete this post.

Sorry for the confusion.

Thanks for the reply walter,
 

barx

Well-Known Member
Licensed User
Longtime User
Anyone any tips for getting this working, thanks
 

barx

Well-Known Member
Licensed User
Longtime User
Bump!

Any hints?
 

barx

Well-Known Member
Licensed User
Longtime User
Is this a permanent feature Erel or is this likely to change in the future, Maybe ContextMenu could be added to core features to replace the .addMenu?
 

barx

Well-Known Member
Licensed User
Longtime User
It's a context menu to use like a right-click on pc that is usually implemented with a longClick

ContextMenu | Android Developers

I guess there are other ways to achieve this including the method tds created which is basically a input dialog without the radio's.

In fact the more I think about it the more it is probably best left out. It has to be registered to a particular view, where as other solutions allow for more dynamic approach.

Whats your initial thought after looking at the documentation linked above?
 

barx

Well-Known Member
Licensed User
Longtime User
OK.

I set about this library as I thought it would be an easy one to get a little library knowledge as I haven't played with libraries for a while.

Don't know why I even asked if it could be added as the dialog from thedesolatesoul does the trick.

Thanks anyway. :)
 
Top