Справка по макету вкладки Android

1

Я работаю над приложением Andriod Tab Layout, чтобы использовать его для программирования andriod. Я знаю, что в этом учебнике много вопросов, но я, похоже, не могу найти, что не так. Ниже приведен код, который у меня есть. Также как я могу получить журналы ошибок? - Я замечаю, что все сообщения задают. Я запускаю его на телефоне andriod, а моя IDE - затмение. Он компилируется отлично, но когда я его запускаю, я получаю черный экран с закрывающей коробкой силы. Спасибо заранее!

Мой основной файл java:

    package greg.tab;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TextView;

public class tab extends TabActivity {
     /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable 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, ArtistsActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                res.getDrawable(R.drawable.ic_tab_artists))
                .setContent(intent);
        tabHost.addTab(spec); 

        //Create an indent
        intent = new Intent().setClass(this, SongActivity.class);
        //Initialize

        spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists))
        .setContent(intent);
        tabHost.addTab(spec);


        //Create an indent
        intent = new Intent().setClass(this, AlbumActivity.class);
        //Initialize

        spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists))
        .setContent(intent);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(2);     
    }

    public class ArtistsActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview = new TextView(this);
            textview.setText("This is The Artists tab");
            setContentView(textview);
        }
    }

    public class AlbumActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview = new TextView(this);
            textview.setText("This is The Album tab");
            setContentView(textview);
        }
    }
    public class SongActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview = new TextView(this);
            textview.setText("This is The song tab");
            setContentView(textview);
        }
    }
}

- Мой XML-манифест

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="greg.tab"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".tab"
                  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=".ArtistsActivity"
android:label ="@string/app_name">
</activity>
<activity android:name=".AlbumActivity"
android:label ="@string/app_name"></activity>
<activity android:name=".SongActivity"
android:label ="@string/app_name">
</activity>
    </application>


</manifest>

- мой xml файл, сделанный для моего селектора изображений (я просто использовал обычный XML файл - я надеюсь, что это правильно) - также я использую это для всех вкладок

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">   
 <!-- When selected, use grey -->   
  <item android:drawable="@drawable/ic_tab_artists_grey" 
           android:state_selected="true" />   
            <!-- When not selected, use white-->   
             <item android:drawable="@drawable/ic_tab_artists_white" />
             </selector>

- Мой основной XML файл

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent">
<LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
        <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
        </LinearLayout>
        </TabHost>

Снова любая помощь приветствуется!

Спасибо.

  • 0
    Вставить сообщение logcat.
  • 0
    Похоже, вам нужно начать с основ программирования на Android. Просто просмотрите руководство разработчика Android, и вы узнаете, как проверить logcat.
Показать ещё 1 комментарий
Теги:

1 ответ

2
Лучший ответ

Попробуйте эту ссылку как использовать logcat

Для силы закрытия: проверьте ресурсы (макет + чертежи), идентификатор, который вы указываете в xml и идентификатор, который вы используете в своем коде. очистить проект и запустить его надеюсь эта помощь!

  • 0
    для рисования ресурсов я просто поместил его в папку рисования HDPI, верно? Также спасибо за ссылку для использования logcat - это облегчит отладку
  • 0
    Эй, попробуйте эти учебники, отличные учебники. Надеюсь, они помогут wonton-games.blogspot.com/2010/07/… и realmike.org/blog/2010/12/21/…

Ещё вопросы

Сообщество Overcoder
Наверх
Меню