在Android的菜单项选择活动启动 [英] Android start activity on Menu Item selection

查看:292
本文介绍了在Android的菜单项选择活动启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个班。一个将是一个基本指令屏幕,该屏幕上就会有一个菜单,可以让你去其他类。另一类是MapActivity。我相信问题是,其未发现其他的类。我试过声明的意图,找到类的几个不同的方法。这是我尝试了最新的东西:

I have 2 classes. One will be a basic instructions screen and on that screen it will have a menu that will let you go to the other class. The other class is a MapActivity. I believe the problem is that its not finding the other class. I've tried a few different ways of declaring the intent to find the class. This is the latest thing I've tried:

@Override
public boolean onCreateOptionsMenu(Menu menu){        
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()){
    case R.id.goToMap:
        Intent intent = new Intent();
        intent.setClassName(Main.this, "Map.Class");
        startActivity(intent);
        return true;            
    }
    return false;
}

它的延伸活动和地图类的基类是扩展MapActivity基本类(可以导致一个问题呢?)。这里是我的清单文件的重要组成部分:

Its a basic class that extends Activity and the map class is a basic class that extends MapActivity (can that cause a problem?). And here is the important part of my Manifest file:

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Campus_Map"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Main" android:label="Instructions" ></activity>
    <activity android:name=".Map" android:label="Map">
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

</application>

编辑:
当在LogCat中寻找弄清楚发生了什么事,我得到一个java.lang.NoClassDefFoundError的和其他一些信息,说阶级./Map链接失败,./Map从方法引用找不到类。 /Main.run和VFY:无法解析常量级37

When looking at the LogCat to figure out what was happening, I'm getting a java.lang.NoClassDefFoundError and a few other messages saying "Link of class ./Map failed", "Could Not find class ./Map referenced from method ./Main.run" and "VFY: unable to resolve const-class 37"

推荐答案

您可以使用像这样的,不要忘了这两个活动添加到AndroidManifest.xml中:

You can use like this and don't forget to add both activities to AndroidManifest.xml:

Intent launchNewIntent = new Intent(CurrentClass.this,SecondClass.class);
startActivityForResult(launchNewIntent, 0);

这篇关于在Android的菜单项选择活动启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆