Android sliding menu force closed - android

I created a sliding menu with the library https://github.com/jfeinstein10/SlidingMenu. I created my own login view instead of slide menu succesfully with the code
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
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.setSecondaryMenu(R.layout.login);
}}
Now I want to make some action in login.SO how can I do this.I tried within the same main activty. but it force closed, how can I do some action in login and where should I code ?? I am new to android so please help me and thanks :)

I had the same problem.Please check Slidingmenu.java in the library and make your code in function public void setsecondarymenu()
eg: if you want to settext to a textview
public void setSecondaryMenu(int res) {
setSecondaryMenu(LayoutInflater.from(getContext()).inflate(res, null));
TextView tv=(TextView)findViewById(R.id.tv);
tv.setText("helloo i got it :)");
}
make sure that u have a layout in library that you want to view
hope this will help you :)

Related

How to use jfeinstein10/SlidingMenu both sides

First of all I am sorry to ask repeated questions. As this has been asked before but some how I could not understand properly.
I found a good solutions here. I followed and could add library to my project. Now I need to add left and right sliding menus to my project without action-bar. Here is the picture-
If I click any of the selected button then it should open the respective sliding page(once at a time) at the specific sides. Something like -
currently -
I am able to generate one side of the menu bar. It is working with sliding only. -
public class MainActivity extends FragmentActivity {
ViewPager viewPager;
PagerAdapter adapter;
CirclePageIndicator mIndicator;
private int mWidthScreen;
private int mHeightScreen;
private Bundle bundle;
private List<Fragment> frgScreens;
private int selectedtheme;
private Handler mHandler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from viewpager_main.xml
setContentView(R.layout.viewpager_main);
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
}
Now I want in both sides and should open menu by clicking the button
Any help will be appreciated. Please feel free to ask any queries.
Well Finally I did it. Here mBtnMenu is an ImageView.
mBtnMenu = (ImageView) findViewById(R.id.btnMenu);
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
mBtnMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// menu.showMenu();
menu.toggle();
}
});

Android view jfeinstein SlidingMenu top of layouts without move content

by default jfeinstein SlidingMenu move content to view slide menu layout, but i dont like that and i want to view slide menu without move content and top of all layouts.
in this below screen shot i like number 2
Default settings are :
public class SlidingExample extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.attach);
// set the content view
setContentView(R.layout.content);
// configure the SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
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.setMenu(R.layout.menu);
}
}
and i'm could not find whats setting view slide menu top of all layouts ans widgets after any testing attachToActivity
wild guess (I don't use jFeinstein)..
when the slider activates, to remove the 'hamburger' icon from the ABar get rid of "home_as_up"...
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_USE_LOGO |ActionBar.DISPLAY_HOME_AS_UP,
ActionBar.DISPLAY_HOME_AS_UP
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO);

jfeinstein10/SlidingMenu attaching a Fragment

I'm trying to implement the jfeinsteins sliding menu, however I'm having a problem getting a fragment to attach. The issue is that the layout is shown on the screen twice. I assume that this is because I setMenu and then do the replace (adding it again).
Could anyone provide some pointers please.
public void configureSlidingMenu()
{
// configure the SlidingMenu
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setFadeDegree(0.35f);
menu.setBehindOffset(120);
menu.setMenu(R.layout.fragment_slideoutmenu);
getFragmentManager()
.beginTransaction()
.replace(R.id.slideOutMenu, new SlideOutMenu())
.commit();
}
I did this in my application...
Created a class Util like this:
public class Util {
public static void atachLeftMenu(final Activity pActivity){
final SlidingMenu menu = new SlidingMenu(pActivity);
menu.setMode(SlidingMenu.LEFT);
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(pActivity, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.side_menu);
( (ListView)(menu.findViewById(R.id.side_menu_list)) ).setAdapter(new leftMenuAdapter(pActivity));
( (ListView)(menu.findViewById(R.id.side_menu_list)) ).setOnItemClickListener( new DrawerItemClickListener(pActivity));
//Set menu options and values
}
}
And in every Activity i just call the Util's "atachLeftMenu" method.
Util.atachLeftMenu(this);
If you want to do it within a fragment you'll still have to pass it the activity so you could do something like this:
Util.atachLeftMenu(getActivity());

How can i move to any other activity with jfeinstein slider library

I have implemented jfeinstein10 slider menu library in my application. With this piece of code I am successfully able to implement slider in my app.
Now my question is how can I move to next activity using this slider? The following image shows how my slider looks like:
So basically I want to move to next activity or any other activity when I click on any of the options from slider. Like for example, when I click on Comment or Post or Chat or any other option I want to go to the relevant screen. Hope this is clear. Still if you need more explanation you can ask.
Following is my code snippet.
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.5f);
menu.attachToActivity(MainActivity.this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.activity_menu);
Button mButton = (Button) findViewById(R.id.slidingMenu);
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
menu.showMenu();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
You can define the onclick listenrs to the Menu layout that you have appended to the Main Activity like so:
menu.getMenu().findViewById(R.id.yourSideMenuOption).setOnClickLister(this);
Its advisable to use an abstract activity, so that you are not using the same code over and over in each of your activity.

SlidingMenu and header

I begin to use a slidingMenu. In my application I have a header with button. when I move it sliding, than my header move too. But I want, than my header do not move, and sliding menu move under header. My header is not actionBar, usual layout.
// configure the SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
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.setMenu(R.layout.menu);
How I can do what I want?
You have to assign a button to action toggle from sliding.
findViewById(R.id.buttonToggle).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
getSlidingMenu().toggle(true);
}
});

Categories

Resources