Hello all, it's been a while since i've posted anything, i was wondering if the experts could help me figure this out.
I'am trying to wrap this library here so far i've gotten pretty much everything working, but i'm getting the error below when trying to open the menu.
I saw this library a very long time ago but i failed miserably to wrap it at that time, i've decided to give it another try and this time i've almost gotten it to work completely, i just need to figure out the error below.
below is the java code for the class i'm working with.
Any help to figure why this is happening will be greatly appreciated, i've never done anything with Fragments, so i'm sort of flying blind here, i'am however glad i've gotten the library to work fine except for when i press on the button to open the menu, then i get this error.
Thanks all
Walter
I'am trying to wrap this library here so far i've gotten pretty much everything working, but i'm getting the error below when trying to open the menu.
I saw this library a very long time ago but i failed miserably to wrap it at that time, i've decided to give it another try and this time i've almost gotten it to work completely, i just need to figure out the error below.
java.lang.NoClassDefFoundError: com.yalantis.contextmenu.lib.MenuAdapter$3
at com.yalantis.contextmenu.lib.MenuAdapter.<init>(MenuAdapter.java:297)
at com.yalantis.contextmenu.lib.ContextMenuDialogFragment.initDropDownMenuAdapter(ContextMenuDialogFragment.java:133)
at com.yalantis.contextmenu.lib.ContextMenuDialogFragment.onCreateView(ContextMenuDialogFragment.java:105)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
below is the java code for the class i'm working with.
B4X:
package com.genesis.contextmenu;
import java.util.ArrayList;
import java.util.List;
import com.yalantis.contextmenu.lib.ContextMenuDialogFragment;
import com.yalantis.contextmenu.lib.MenuObject;
import com.yalantis.contextmenu.lib.MenuParams;
import com.yalantis.contextmenu.lib.interfaces.OnMenuItemClickListener;
import com.yalantis.contextmenu.lib.interfaces.OnMenuItemLongClickListener;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DontInheritEvents;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@ShortName("ContextMenu")
@Version(1.49f)
@ActivityObject
@Events(values = { "MenuItemClick (item As MenuItem)" })
@DontInheritEvents
@Author(value = "Walter Flores")
public class B4AContextMenu extends AppCompatActivity implements OnMenuItemClickListener, OnMenuItemLongClickListener {
private FragmentManager fragmentManager;
private ContextMenuDialogFragment mMenuDialogFragment;
private int actionbarsize;
private static BA mba;
private String mEventName;
public void Initialize(BA ba, String eventname, int actionBarSize){
mEventName = eventname.toLowerCase(BA.cul);
actionbarsize = actionBarSize;
mba = ba;
fragmentManager = ((AppCompatActivity)mba.activity).getSupportFragmentManager();
BA.Log("fragment manager: " + fragmentManager.getBackStackEntryCount());
BA.Log("after fragmentManager");
Toolbar(toolbar.getObject().getContext());//toolbar.getObject();
initToolbar();
initMenuFragment();
}
public void addfragment(BA ba){
int containerres;
String container;
container = "container";
containerres = BA.applicationContext.getResources().getIdentifier(container, "id", BA.packageName);
BA.Log("container resource found: " + containerres);
addFragment(new MainFragment(), true, containerres);
}
private void initMenuFragment() {
MenuParams menuParams = new MenuParams();
menuParams.setActionBarSize(actionbarsize);
menuParams.setMenuObjects(getMenuObjects());
menuParams.setClosableOutside(false);
mMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams);
mMenuDialogFragment.setItemClickListener(this);
mMenuDialogFragment.setItemLongClickListener(this);
}
private List<MenuObject> getMenuObjects() {
List<MenuObject> menuObjects = new ArrayList<MenuObject>();
int closemenu;
String closeicon;
closeicon = "icn_close";
closemenu = BA.applicationContext.getResources().getIdentifier(closeicon, "drawable", BA.packageName);
BA.Log("icon close resource: " + closemenu);
MenuObject close = new MenuObject();
close.setResource(closemenu);
int sendicon;
String sendstring;
sendstring = "icn_1";
sendicon = BA.applicationContext.getResources().getIdentifier(sendstring, "drawable", BA.packageName);
MenuObject send = new MenuObject("Send Message");
send.setResource(sendicon);
int likeicon;
String likestring;
likestring = "icn_2";
likeicon = BA.applicationContext.getResources().getIdentifier(likestring, "drawable", BA.packageName);
MenuObject like = new MenuObject("Like profile");
like.setResource(likeicon);
menuObjects.add(close);
menuObjects.add(send);
menuObjects.add(like);
return menuObjects;
}
private void initToolbar() {
int toolres;
String toolbarstring;
toolbarstring = "toolbar";
toolres = BA.applicationContext.getResources().getIdentifier(toolbarstring, "id", BA.packageName);
BA.Log("Toolbar resource found: " + toolres);
Toolbar mToolbar = (Toolbar)mba.activity.findViewById(toolres);
((AppCompatActivity)mba.activity).setSupportActionBar(mToolbar);
if (((AppCompatActivity) mba.activity).getSupportActionBar() != null) {
((AppCompatActivity) mba.activity).getSupportActionBar().setHomeButtonEnabled(true);
((AppCompatActivity) mba.activity).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((AppCompatActivity) mba.activity).getSupportActionBar().setDisplayShowTitleEnabled(false);
}
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem arg0) {
// TODO Auto-generated method stub
BA.Log("inside onMenuItemClick: " + arg0.toString());
mba.raiseEventFromUI(this, mEventName + "_menuitemclick", new Object[] {new MenuItemWrapper(arg0)});
return true;
}
});
//mToolBarTextView.setText("Samantha");
}
public void OpenMenu(BA ba, MenuWrapper menu1){
int menu;
String menuinflate;
menuinflate = "menu_main";
menu = BA.applicationContext.getResources().getIdentifier(menuinflate, "menu", BA.packageName);
BA.Log("menu layout found: " + menu);
MenuInflater inflater = ((AppCompatActivity)mba.activity).getMenuInflater();
inflater.inflate(menu, menu1.getObject());
}
[/COLOR]
//This is where the app crashes and gives me the error right at this function.
[COLOR=rgb(0, 0, 0)] public void ShowMenu(BA ba){
mMenuDialogFragment.show(fragmentManager, "ContextMenuDialogFragment");
}
protected void addFragment(Fragment fragment, boolean addToBackStack, int containerId) {
BA.Log("inside addfragment sub");
((AppCompatActivity)mba.activity).invalidateOptionsMenu();
String backStackName = ((AppCompatActivity)mba.activity).getClass().getName()
BA.Log("fragment Name: " + backStackName);
boolean fragmentPopped = fragmentManager.popBackStackImmediate(backStackName, 0);
BA.Log("fragmentPopped: " + fragmentPopped);
if (!fragmentPopped) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
BA.Log("before adding transaction");
transaction.add(containerId, fragment, backStackName)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
if (addToBackStack)
transaction.addToBackStack(backStackName);
transaction.commit();
BA.Log("done executing addFragment");
}
}
@Override
public void onMenuItemLongClick(View clickedView, int position) {
// TODO Auto-generated method stub
}
@Override
public void onMenuItemClick(View clickedView, int position) {
// TODO Auto-generated method stub
BA.Log("item clicked: " + position);
}
}
Any help to figure why this is happening will be greatly appreciated, i've never done anything with Fragments, so i'm sort of flying blind here, i'am however glad i've gotten the library to work fine except for when i press on the button to open the menu, then i get this error.
Thanks all
Walter