0
嘿即时通讯开发我的第一个适当的android应用程序,并已遇到2小型混乱,并希望得到一些帮助basicaly主要问题是,我似乎不能从tabhost更改为新视图。我有4个选项卡2只显示一个简单的XML文件第三显示了一系列图片,我想使它们可点击,以便他们扩大到球员生物的。 atm im试图以下面的方式做到这一点,但它只是导致我的应用程序崩溃从tabhost打开一个新窗口
package com.BPRUFC;第一张图后
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
public class BPRUFCAppActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Fixtures").setContent(R.id.fixtures));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Results").setContent(R.id.results));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Players").setContent(R.id.bio));
mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Tour").setContent(R.id.tour));
mTabHost.setCurrentTab(0);
int days = 184;
String tour2 = getString(R.string.tour, days);
}
public void clicked(View view)
{
Intent myIntent = new Intent(BPRUFCAppActivity.this, PlayerBio.class);
BPRUFCAppActivity.this.startActivity(myIntent);
}
}
主要的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">
<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">
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/fixtures"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/fixtures" />
</ScrollView>
<TextView
android:id="@+id/results"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Results go here" />
<ScrollView
android:id="@+id/ScrollView02"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/bio"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="90dip"
android:layout_height="90dip"
android:id="@+id/imageView1"
android:src="@drawable/forrest"
android:onClick="clicked"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp">
</ImageView>
感谢和我确定它是一个小白错误
请提供堆栈轨道,以便我们看到它崩溃的位置。 – Fred
修正了我错误的方式嵌套太多的布局我改变了所有,所以每个选项卡有1个框架布局,然后相应地修改它现在行为正常 – watersa8