android tabview应用程序错误

发布于 2025-01-05 07:50:06 字数 3316 浏览 0 评论 0原文

我试图让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉世弥音 2025-01-12 07:50:06

我确信 AndroidManifest.xml 文件中存在问题(不是问题,而是错误)。错误在于您已将所有 4 个活动定义为启动器活动,而不是只需将一个活动定义为启动器活动。

例如:

<activity android:name=".MainActivity">

          <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
   </activity>

并从其他活动中删除 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:

<activity android:name=".MainActivity">

          <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
   </activity>

And remove MAIN and LAUNCHER from other activities.

空城仅有旧梦在 2025-01-12 07:50:06

在清单文件中,您声明了多个不正确的 LAUNCHER 活动。查看更多此处

In manifest file you declared more than one LAUNCHER activity that is not correct. look more here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文