有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何将活动链接到菜单并访问它们

i have created a project with a menu (not empty project) that should open an list of my activities (and it does that) but when i want to open one of the activities that is already shown it doest work. It doesnt open the specified activity but instead it opens the main activity and so on, how can i link them up ? . Thanks.

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.nav_calendar) {
        Intent i=new Intent(this, Calendar.class);
        startActivity(i);
    }
    if (id == R.id.nav_info) {
        Intent i=new Intent(this, CarInfo.class);
        startActivity(i);
    }

    if (id == R.id.nav_expenses) {
        Intent i=new Intent(this, Expenses.class);
        startActivity(i);
    }
    if (id == R.id.nav_map) {
        Intent i=new Intent(this, Map.class);
        startActivity(i);
    }
    if (id == R.id.nav_service) {
        Intent i=new Intent(this, Service.class);
        startActivity(i);
    }

    return super.onOptionsItemSelected(item);
}

That's how i link every of my activity to menu. I tried this too still doesnt do what i like: I tried to link them like that :

public void CarInfo(View view){
Intent intent=new Intent(MainActivity.this, CarInfo.class);
startActivity(intent);

}

我认为问题可能在舱单上:

 <application
    安卓:allowBackup="true"
    安卓:icon="@mipmap/ic_launcher"
    安卓:label="@string/app_name"
    安卓:supportsRtl="true"
    安卓:theme="@style/AppTheme">
    <activity 安卓:name=".MainActivity">
        <intent-filter>
            <action 安卓:name="安卓.intent.action.MAIN" />

            <category 安卓:name="安卓.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity 安卓:name=".Calendar"></activity>
    <activity 安卓:name=".CarInfo"></activity>
    <activity 安卓:name=".Expenses"></activity>
    <activity 安卓:name=".History"></activity>
    <activity 安卓:name=".Map"></activity>
    <activity 安卓:name=".Service"></activity>
</application>

如果我只把一个活动链接到它的作品上,那我怎么能把它们都链接起来呢


共 (0) 个答案