InnocentKiller
InnocentKiller

Reputation: 5234

How can i go to next screen while using sliding menu

I am using this library project to implement sliding menu and now i am successfully able to implement it. When i click button it open's sliding menu and now My question is how can i go to any other activity by clicking menu option.

I want when i click on My Profile it takes me to that screen, then if i click Profile Picture then some other screen etc... etc...

Below is my code.

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;
    }
}

Edit

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/option_popup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/settingMenu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#262E38"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/setting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/settings" />

        <ImageView
            android:id="@+id/myprofile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/setting"
            android:src="@drawable/myprofile" />

        <ImageView
            android:id="@+id/profilepicture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/myprofile"
            android:src="@drawable/profilepicture" />

        <ImageView
            android:id="@+id/changewallpaper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/profilepicture"
            android:src="@drawable/changewallpaper" />

        <ImageView
            android:id="@+id/notification"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/changewallpaper"
            android:src="@drawable/notofication" />

        <ImageView
            android:id="@+id/comment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/notification"
            android:src="@drawable/commentstrip" />

        <ImageView
            android:id="@+id/post"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/comment"
            android:src="@drawable/post" />

        <ImageView
            android:id="@+id/chat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/post"
            android:src="@drawable/chat" />

        <ImageView
            android:id="@+id/likedislike"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/chat"
            android:src="@drawable/likeanddislike" />

        <ImageView
            android:id="@+id/privacypolicy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/likedislike"
            android:src="@drawable/privacypolicy" />

        <ImageView
            android:id="@+id/termscondition"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/privacypolicy"
            android:src="@drawable/termscondition" />

        <ImageView
            android:id="@+id/contactus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/termscondition"
            android:src="@drawable/contactus" />

        <ImageView
            android:id="@+id/logout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/contactus"
            android:src="@drawable/logout" />
    </RelativeLayout>

</ScrollView>

Upvotes: 0

Views: 603

Answers (4)

cesztoszule
cesztoszule

Reputation: 306

Hmm something like this, just a quick pseudo code, you can do the rest.

@Override
public boolean onOptionsItemSelected(MenuItem item) {

      switch(item.getItemId()){
       case R.id.profile:
        profile();
        break;
       case R.id.logout:
        logout();
        break;
     }
 return super.onOptionsItemSelected(item);
}

Upvotes: 1

ElaGorilaki
ElaGorilaki

Reputation: 227

You should also override the onOptionsItemSelected method, from the Activity Class.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    case R.id.myProfile:
        showMyProfile();
        return true;
    case R.id.profilePicture:
        profilePicture();
        return true;
    case R.id.changeWallpaper:
        changeWallpaper();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }

Then you can create the corresponding methods where you will initialize your intents

public void profilePicture() {
Intent intent = new Intent(this,ProfilePicture.class);
startActivity(intent);

Upvotes: 0

user8938
user8938

Reputation: 559

Use the following code

 View op1 = findViewById(R.id.op1);
 op1.setOnClickListener(new OnClickListener() 
 {
  startActivity(this, YourActivity.class);
 }}
 );

Upvotes: 0

Dhinakaran Thennarasu
Dhinakaran Thennarasu

Reputation: 3356

private void displayView(int position) 
{
        Fragment fragment = null;
        switch (position) {
        case 0:
            fragment = new MyProfile();
            Toast.makeText(getApplicationContext(), ""+position, Toast.LENGTH_SHORT).show();
            break;
        case 1:
            fragment = new ProfilePicture();
            Toast.makeText(getApplicationContext(), ""+position, Toast.LENGTH_SHORT).show();
            break;

        default:
            break;
        }

Refer this link

Use switch case.. using position once you click an item it will take you to that particular class.

Upvotes: 0

Related Questions