Android的标签教程麻烦 [英] Android Tab Tutorial Trouble
问题描述
我刚刚发现我的错误,通过调试遍地找一遍,但无论如何之后,感谢大家!!
有我是很新的Android和通过一些教程是工作。现在,我被困在标签教程。在code似乎乍一看罚款,我没有得到任何错误,但是当我尝试运行它总是崩溃模拟器中的应用程序,我得到一个应用程序意外停止错误消息。
Hi there, I am very new to Android and was working through some tutorials. Now I got stuck at the Tab tutorial. The code seems to be fine at first glance as I am not getting any errors, but when I try to run the app on the emulator it always crashes and I get an "application stopped unexpectedly" error message.
我已经尝试过什么是在有关标签布局问题讨论说,但我所做的更改不与错误帮助。如果有人能帮助我与,这将绝对好吃。如果你想看到的code,只是告诉我,如果我应该张贴或发送。
I already tried what was said in the discussion about the tab layout problem, but the changes I made didn't help with the error. If someone can help me with that, that would absolutely great. If you would like to see the code, just tell me if I should post or send it.
感谢ü提前。
这是我的code为的Manifest.xml 文件,因为我不知道,如果我做错了事有:
This is my code for the Manifest.xml file because I am not sure, if I have done something wrong there:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobilevideoeditor.moved"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".GalleryView" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".ShareGalleryView" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"> </activity>
<activity android:name=".EditGalleryView" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"> </activity>
</activity>
</application>
</manifest>
这是在 GalleryView.java 文件:
package com.mobilevideoeditor.moved;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class GalleryView extends TabActivity {
/** Called when the activity is first created. */
@Override
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; // 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, EditGalleryView.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("edit").setIndicator("Edit",
res.getDrawable(R.drawable.ic_tab_edit))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ShareGalleryView.class);
spec = tabHost.newTabSpec("share").setIndicator("Share",
res.getDrawable(R.drawable.ic_tab_share))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
下面是code为的main.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>
在code为 EditGalleryView.java 和 ShareGalleryView.java
package com.mobilevideoeditor.moved;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ShareGalleryView extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Share tab!");
setContentView(textview);
}
}
和最后code为 ic_tab_share.xml 和 ic_tab_edit.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use ic_tab_share (grey icon) -->
<item android:drawable="@drawable/ic_tab_share"
android:state_selected="true" />
<!-- When not selected, use ic_tab_share_unselected (white icon)-->
<item android:drawable="@drawable/ic_tab_share_unselected" />
</selector>
再次感谢:)
推荐答案
我有一个类似的问题当我第一次尝试跳布局教程从官方开发者的网站。
I had a similar problem when I first tried the Tab Layout Tutorial from official developer's site.
既然你运行这将是最有可能是由于在AndroidManifest.xml文件不加入活动的应用程序获得了强制关闭的错误。
Since you are getting the 'force close' error on running the application it would be most probably due to not adding the activities in AndroidManifest.xml file.
这篇关于Android的标签教程麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!