Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用滑动菜单时如何转到下一屏幕_Android_Onclick_Slidingmenu - Fatal编程技术网

Android 使用滑动菜单时如何转到下一屏幕

Android 使用滑动菜单时如何转到下一屏幕,android,onclick,slidingmenu,Android,Onclick,Slidingmenu,我正在使用库项目来实现滑动菜单,现在我能够成功地实现它。当我点击按钮时,它会打开滑动菜单,现在我的问题是如何通过点击菜单选项进入任何其他活动 我想当我点击我的个人资料时,它会把我带到那个屏幕,然后如果我点击个人资料图片然后是其他屏幕等等。。。等等 下面是我的代码 public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) {

我正在使用库项目来实现滑动菜单,现在我能够成功地实现它。当我点击按钮时,它会打开滑动菜单,现在我的问题是如何通过点击菜单选项进入任何其他活动

我想当我点击
我的个人资料
时,它会把我带到那个屏幕,然后如果我点击
个人资料图片
然后是其他屏幕等等。。。等等

下面是我的代码

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

<?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>

使用以下代码

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


使用开关箱。。使用“位置”单击某个项目后,它会将您带到该特定类

嗯,类似这样的东西,只要一个快速的伪代码,您就可以完成其余的工作

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

您还应该从Activity类重写OnOptions ItemSelected方法

@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);
    }
然后可以创建相应的方法,在其中初始化意图

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


你能发布R.layout.activity_菜单吗?@blackbelt,检查我的编辑。尝试方式我没有正确地理解你,请简单解释一下。我的意思是你想在菜单项单击上执行事件。我说得对吗?是的,当我点击任何选项时,我只想移动到下一个屏幕,就是这样。如果你点击滑动菜单中的注释,它将打开注释页面,但在这种情况下,什么是
op1
,我需要在点击事件中执行什么操作。哎呀。。如果你使用片段IMHO,这很容易。。只需使用开关的情况下有多少类你想,!!它在
开关(item.getID())
上给出错误,错误是,
类型MenuItem的方法getID()未定义
这是一个伪代码,不是精确的代码:)它不是getID()它的getItemId()它说了什么错误?它应该有用。。另一个版本是,你有一个列表,填充你的滑动菜单项,并设置onItemClick,但我没有看到你这样做,所以还有一些其他的。。。在这个方法中是否返回true?让我编辑代码。。。首先让我澄清一件事,我并没有实现菜单应用程序,我正在尝试实现滑动菜单,我做到了,现在的问题是,当点击滑动菜单屏幕时,我想打开新的活动。它不起作用。当点击选项nothing happens时,您可以发布菜单xml吗?因为我认为您没有引用正确的xml。我在menu.xml中没有任何内容,我正在实现滑动菜单,并且我已经在上面的代码中列出了该xml。您是否创建了您想要的类?如果是,这些活动有什么作用吗?是的,我已经创建了类,但是当我实现你的代码时,它不会带我进入新的屏幕。
public void profilePicture() {
Intent intent = new Intent(this,ProfilePicture.class);
startActivity(intent);