android tabview应用程序错误
我试图让 tabview 应用程序工作,它在 eclipse 模拟器中工作正常,但是当尝试在设备中安装时,它创建了四个应用程序,每个应用程序都有不同的活动,在选项卡应用程序中使用,是否曾经发生过这种问题对任何人。
主要活动中的一些代码:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistActivity.class);
spec = tabHost.newTabSpec("main").setIndicator("Main", res.getDrawable(R.drawable.ic_tab_main)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, AlbumActivity.class);
spec = tabHost.newTabSpec("camera").setIndicator("Camera", res.getDrawable(R.drawable.ic_tab_camera)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("livemap").setIndicator("Live Map", res.getDrawable(R.drawable.ic_tab_livemap)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
xml 文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tablayout.testing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".TabLayoutDemoActivity"
android:theme="@android:style/Theme.NoTitleBar"
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=".mainActivity"
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=".cameraActivity"
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=".mapActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I trying to get the tabview app to work, its working fine in the eclipse emulator, but when trying to install in the device its creating four application each of different activity, that is used in the tab application, did this kind of problem ever occurred to anyone.
some of the code from main activity:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistActivity.class);
spec = tabHost.newTabSpec("main").setIndicator("Main", res.getDrawable(R.drawable.ic_tab_main)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, AlbumActivity.class);
spec = tabHost.newTabSpec("camera").setIndicator("Camera", res.getDrawable(R.drawable.ic_tab_camera)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("livemap").setIndicator("Live Map", res.getDrawable(R.drawable.ic_tab_livemap)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tablayout.testing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".TabLayoutDemoActivity"
android:theme="@android:style/Theme.NoTitleBar"
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=".mainActivity"
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=".cameraActivity"
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=".mapActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确信 AndroidManifest.xml 文件中存在问题(不是问题,而是错误)。错误在于您已将所有 4 个活动定义为启动器活动,而不是只需将一个活动定义为启动器活动。
例如:
并从其他活动中删除 MAIN 和 LAUNCHER。
I am sure there is an issue (not an issue, but a mistake) inside the AndroidManifest.xml file. Mistake is that you have defined all 4 activity as a Launcher activity, instead of that you just have to define only one activity as a Launcher activity.
For example:
And remove MAIN and LAUNCHER from other activities.
在清单文件中,您声明了多个不正确的 LAUNCHER 活动。查看更多此处
In manifest file you declared more than one LAUNCHER activity that is not correct. look more here