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

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.

Related

Options menu persists in the second activity

After clicking a button to open a new Activity using this method:
setContentView(R.layout.activity_comunidades01);
The second Activity still display the same menu as the previous one.
I have already readed serval methods to fix it as the one related in here:
Android: How to enable/disable option menu item on button click?
But I discovered that the methods to intialize and create the menu are never called. I even try to follow this other link without success:
onCreateOptionsMenu is never called
I even deleted all the items in the menu.xml for this activity but still displaying the previous activity options.
I also clarify I am using android 4.4 as target API but level 10 as a minimum one since some devices that will be used are running android 2.3.
My second Activity is like this:
public class SecondActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_SecondActivity);
}
#Override
public boolean onPrepareOptionsMenu(Menu menu){
System.out.println("EN ON PREPARE OPTIONS MENU");
(menu.findItem(R.id.sincronizar)).setEnabled(false);
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
System.out.println("EN ON CREATE OPTIONS MENU");
getMenuInflater().inflate(R.menu.SecondActivity, menu);
return true;
}
}
To start second activity use this:
Button bt = (Button)findViewById(R.id.bt);
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
//finish(); //if you want to close FirstActivity after showing SecondActivity
}
});
After clicking a button to open a new Activity using this method:
setContentView(R.layout.activity_comunidades01)
This is not how you open another activity!
This way you only change the content of the current activity, nothing else.
Use Activity.startActivity() or Activity.startActivityForResult() as described in the docs to start another activity.

Shortcut to settings android

I'm interested about how is possible create a shortcut to different items of settings in android devices.
Specifically to advances settings of mobile data.
I want to do an app that allows user a quick access to switch menu 2g-3g.
I know that the app dosen't do switch, I only want the shorcut to this menu.
I don't know how It's made!
I'm very glad if somebody help me!
Thanks a lot!!!
public class MainActivity extends Activity implements OnClickListener
{
Button boton;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
boton = (Button) findViewById(R.id.boton);
boton.setOnClickListener(this);
}
#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;
}
#Override
public void onClick(View v)
{
if(v.getId() == R.id.boton)
{
startActivity(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS));
}
}
}
I do this code by the explanation of Seraphim but dosen't work.
To switch to the 2G/3G settings page use this code inside the Button click handler:
startActivity(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS));
or others, look at:
http://developer.android.com/reference/android/provider/Settings.html
Other interesting are:
android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS
android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS
android.provider.Settings.ACTION_WIRELESS_SETTINGS
android.provider.Settings.ACTION_APN_SETTINGS
i would like to suggest u that refer this three link(FIRST,SECOND,THIRD) and u would be able to change most of the settings by ur own . ANDROID SETTINGS mostly stores there respective values to this three tables.
If you want to enable or disable GPS than use
Settings.Secure.setLocationProviderEnabled(cr, LocationManager.GPS_PROVIDER, true);

On click interraction between screens android

I have created 2 main activity.java files in my source file.
In the first one i make the first screen appear and when i click a button i want to go
to another activity in order to get the second screen appear.
That's why i have created my MainActivity2.java file that is triggered when i click a button.
Although i have no compile errors, when i run my app it stops in the simulator and it does not even show the first screen. The code is the following :
MainActivity.java :
public class MainActivity extends Activity implements OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button imageButton1 = (Button) findViewById(R.id.imageButton1);
imageButton1.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View v) {
Intent i=new Intent(MainActivity.this, MainActivity2.class);
startActivity(i);
}
}
and for
MainActivity2.java :
public class MainActivity2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_2);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
, where activity_main is my first .xml file containing the forst screen and imageButton1 is
the button i have created in my xml file that i want to go to the MainActivity2, when clicked and trigger the second activity in order to show the second screen. And activity_main_2.xml contains the second screen.
Thanks in advance.
First of all, have you declared both of the activities in the manifest file of the application? That might be the reason why the application force closes.
Secondly,
In the onClick method you should check if that button has actually been clicked by checking for the id of the button.
public void onClick(View v) {
if(v.getId()==R.id._idofImageButton_){
Intent i=new Intent(MainActivity.this, MainActivity2.class);
startActivity(i);
}
}
Hope this helps.
First of all check if you have added second Activity to AndroidManifest file. If you did, then please, provide stack trace.

JFEinstien sliding menu unable to set width of the behind view

I was working on implementing the sliding menu.
I want to set the width of the sliding menu as 2/3 of the screen width when active.
Here is my MainActivity
public class MainActivity extends SlidingActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setBehindContentView(R.layout.slidemenu_layout);
setSlidingActionBarEnabled(false);
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.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
menu.setBehindWidth((2*displaymetrics.widthPixels)/3);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getSupportMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
}
return super.onOptionsItemSelected(item);
}
}
*NOTE :*I had initially made MainActivity extend Activity and it was working fine there.
I had to move to SlidingActivity to implement Action Bar Sherlock
EDIT :I replaced SlidingActivity with SherlockActivity and deleted the setBehindContentView(..) and carried on.But no clue why 1st one did not work.
Have you tried using setBehindWidthRes rather than setBehindOffsetRes?
You can try setting the behind width with setBehindOffsetRes, and passing an id from a resource XML, like in this answer.

Sliding menu toggle option

I want to use the menu button on android to make the sliding menu toggle from left to right. The problem I face is that since I have used the sliding menu functionality in my main activity on create method, I do not how to use the same variable in the onPrepareOptionMenu method.
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidth(10);
menu.setBehindOffset(60);
menu.setFadeDegree(0.25f);
menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
menu.setBehindWidth(400);
menu.setMenu(R.layout.menu_frame);
this is the code which I use to call the sliding menu, However, I want to enable the toggle button whenever the menu button is called along side the swipe gesture .
public boolean onPrepareOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
//try to enable the toggle here so that the sliding menu can appear/disappear
return true;
}
The problem is that unlike most cases, I do not extend my main class with the Sherlock activity since my main class is already extending some other activity. Hence I use the sliding menu in form of a constructor(look at my example). I am not sure how to integrate the toggle function. Thank for all the help
If you need override OptionsMenu methods and you want this methods public your Activity, then you first create Activity to Options menu and in you activity need extends CustomOptionMenuActivity.
Example:
1. Create CustomOptionMenuActivity:
public class CustomOptionMenuActivity extends Activity {
private Menu SlidingMenu;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
this.SlidingMenu = menu;
return true;
}
public boolean onPrepareOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
//try to enable the toggle here so that the sliding menu can appear/disappear
return true;
}
}
Then you can use menu in any activities, but you need extends this activity.
Example:
public class MainActivity extends CustomOptionMenuActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
}
}
Good luck!

Categories

Resources