android - Closing Sliding menu onItemClick -


so, i'm using jfeinstein10 library slidingmenu. works fine i'm having problem toggle menu when user taps in 1 of menu options.

i have mainactivty slidingmenu , fragment called samplelistfragment set menu options.

what i'm trying call function mainactivity when click option. function should toggle menu, instead nullpointexception error.

my mainactivity

public class mainactivity extends baseactivity implements slidingactivitybase {  private slidingmenu menu;  private imagebutton btn_pesquisa; private imagebutton btn_toggle;  private makemateria makemat = new makemateria();  private static final int screen_orientation_portrait = 1;  string id_test;  samplelistfragment listfragment = new samplelistfragment();  public mainactivity() {     super(r.string.title_bar_content); }  public void maintoggle() {     log.d("1", "" + this);     toggle();     log.d("2", "" + this); }  public static intent newinstance(activity activity, int pos) {     intent intent = new intent(activity, mainactivity.class);     intent.putextra("pos", pos);     return intent; }  public void testeevent(){     log.d("funciona","works");      toggle(); }  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);        if (build.version.sdk_int < build.version_codes.ice_cream_sandwich) {         bitmapdrawable bg = (bitmapdrawable) getresources().getdrawable(                 r.drawable.titlebar);         bg.settilemodexy(tilemode.repeat, tilemode.repeat);         getsupportactionbar().setbackgrounddrawable(bg);          bitmapdrawable bgsplit = (bitmapdrawable) getresources()                 .getdrawable(r.drawable.titlebar);         bgsplit.settilemodexy(tilemode.repeat, tilemode.repeat);         getsupportactionbar().setsplitbackgrounddrawable(bgsplit);     }      int pos = 0;     if (getintent().getextras() != null) {         pos = getintent().getextras().getint("pos");     }      getsupportactionbar().setdisplayoptions(actionbar.display_show_custom);     getsupportactionbar().setcustomview(r.layout.abs_layout);      menu = new slidingmenu(this);     menu.settouchmodeabove(slidingmenu.touchmode_fullscreen);     menu.setshadowwidthres(r.dimen.shadow_width);     menu.setshadowdrawable(r.drawable.shadow);     menu.setbehindoffsetres(r.dimen.slidingmenu_offset);     menu.setfadedegree(0.35f);     menu.attachtoactivity(this, slidingmenu.sliding_content);     menu.setbehindscrollscale((float) 1.0);     menu.setmenu(r.layout.menu_frame);      // set above view     setcontentview(r.layout.content_frame);     getsupportfragmentmanager().begintransaction()             .replace(r.id.content_frame, new mainfragment()).commit();      setslidingactionbarenabled(true);      btn_pesquisa = (imagebutton) findviewbyid(r.id.btnpesquisa);     btn_toggle = (imagebutton) findviewbyid(r.id.btn_menu);      btn_toggle.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             toggle();          }     });      btn_pesquisa.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             intent intent = new intent(getapplicationcontext(),                     searchactivity.class);             //startactivity(intent);             overridependingtransition(r.anim.view_transition_in_left,                     r.anim.view_transition_out_left);         }     }); }  public void getmenu(){     menu.toggle(); }   @override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {     case android.r.id.home:         toggle();         return true;      default:         return super.onoptionsitemselected(item);     } } 

}

this part fragment:

@override public void onlistitemclick(listview lv, view v, int position, long id) {      fragment newcontent = null;       android.support.v4.app.fragmenttransaction transaction = getfragmentmanager().begintransaction();      switch (position) {     case 0:         log.d("1", "1");                  getfragmentmanager().begintransaction().replace(r.id.content_frame, new mainfragment()).commit();         mainactivity.getmenu();          break;     case 1:         log.d("2", "2");         toggle();         break;     case 2:         log.d("3", "3");         toggle();         break;     case 3:         log.d("4", "4");         toggle();         break;     case 4:         log.d("5", "5");         toggle();         break;     case 5:         log.d("6", "6");         toggle();         break;     case 6:         log.d("7", "7");         toggle();         break;     case 7:         log.d("8", "8");         toggle();         break;     case 8:         log.d("9", "9");         toggle();         break;     }     if (newcontent != null)         switchfragment(newcontent); } 

mainactivity mainactivity global, , insance of did in oncreateview.

the npe points lines call function , call toggle inside function.

many thanks.

i did -> android : accessing container activity object fragment using putextra?

the problem passing null object, when did ->

((mainactivity) this.getactivity()).getmenu() 

i able correct value object.

@wenger help.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -