Java Emulator仅单击上面的…,即可打开所有活动。。。?
我又来了 我的菜单和我的活动有问题 当我运行emulator并单击列表中的uppest项时,emulator将打开所有列表活动 希望有人能帮助我。。提前谢谢大家 我的菜单.Java:Java Emulator仅单击上面的…,即可打开所有活动。。。?,java,android,android-activity,manifest,Java,Android,Android Activity,Manifest,我又来了 我的菜单和我的活动有问题 当我运行emulator并单击列表中的uppest项时,emulator将打开所有列表活动 希望有人能帮助我。。提前谢谢大家 我的菜单.Java: package com.jacob.eindproject; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import and
package com.jacob.eindproject;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity implements OnItemClickListener {
String classes[] = { "BMI- Calculator", "Ondergewicht", "Gezond Gewicht", "Overgewicht"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//Positie 0 is het eerste item (dus de BMI-Calculator.)
super.onListItemClick(l, v, position, id);
switch(position)
{
case 0:
Intent openStartingPoint = new Intent(getApplicationContext(),MainActivity.class);
startActivity(openStartingPoint);
case 1:
Intent openOndergewicht = new Intent(getApplicationContext(),Ondergewicht.class);
startActivity(openOndergewicht);
case 2:
Intent openGezondgewicht = new Intent(getApplicationContext(),Gezond_gewicht.class);
startActivity(openGezondgewicht);
case 3:
Intent openOvergewicht = new Intent(getApplicationContext(),Overgewicht.class);
startActivity(openOvergewicht);
break;
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
package com.jacob.eindproject;
导入android.app.ListActivity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ArrayAdapter;
导入android.widget.ListView;
公共类菜单扩展ListActivity实现了MClickListener{
字符串类[]={“BMI-Calculator”、“Ondergewicht”、“Gezond-Gewicht”、“Overgewicht”};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setListAdapter(新的ArrayAdapter(Menu.this,android.R.layout.simple_list_item_1,classes));
}
@凌驾
受保护的void onListItemClick(列表视图l、视图v、整数位置、长id){
//阳性0为其他项目(体重指数计算器)
super.onListItemClick(左、右、位置、id);
开关(位置)
{
案例0:
Intent openStartingPoint=newintent(getApplicationContext(),MainActivity.class);
启动触觉(打开启动点);
案例1:
Intent openOndergewicht=新Intent(getApplicationContext(),Ondergewicht.class);
startActivity(openOndergewicht);
案例2:
Intent openGezondgewicht=新Intent(getApplicationContext(),gezondu gewicht.class);
startActivity(openGezondgewicht);
案例3:
Intent openOvergewicht=新Intent(getApplicationContext(),Overgewicht.class);
startActivity(openOvergewicht);
打破
}
}
@凌驾
public void onItemClick(AdapterView arg0、视图arg1、整型arg2、长型arg3){
//TODO自动生成的方法存根
}
}
这是我的舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jacob.eindproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.jacob.eindproject.Menu"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.jacob.eindproject.Inleiding"
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="com.jacob.eindproject.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Ondergewicht"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.ONDERGEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Gezond_gewicht"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.GEZOND_GEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="com.jacob.eindproject.Overgewicht"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.jacob.eindproject.activity.OVERGEWICHT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
首先,打开Inleiding,它是我的徽标,5秒钟后它消失了
之后,我希望菜单包含4项,1项用于MainActivity.java,这是一个BMI计算器。最后3项是关于重量和材料的信息项
知道答案的人
感谢大家的努力。之所以所有活动都打开,是因为您的
开关中的每个案例
子句末尾没有break
语句。您需要在每个案例
块的末尾添加一个中断
此外,除了包含CATEGORY=DEFAULT
和ACTION=MAIN
的第一个(Inleiding
)标记外,您还应该从所有活动中删除
标记。你不需要这些,它们只会让你困惑