我按照Android网站中的示例创建了包含多个活动的标签活动。现在我试图将它作为单个活动和多个视图。我收到以下异常
Java.lang.RuntimeException:无法创建标签内容,因为无法按ID找到视图
这是我的布局文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootTbl" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost 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="wrap_content"
android:layout_weight="1"/>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/assignedLin" >
<TextView android:id="@+id/dateassigned" style="@style/deftxtView"/>
<ListView android:id="@+id/assignedListView" android:layout_width="match_parent" android:layout_height="300dp"/>
</LinearLayout>
<!--TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/assignedTbl" >
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/dateassigned" style="@style/deftxtView"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="@+id/assignedListView" android:layout_width="match_parent" android:layout_height="300dp"/>
</TableRow>
</TableLayout-->
<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/acceptedTbl" >
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/dateaccepted" style="@style/deftxtView"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="@+id/acceptedListView" android:layout_width="match_parent" android:layout_height="300dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
这是我的java文件
package com.tcs.mServices;
import java.util.ArrayList;
import com.tcs.mLib.DBAdapter;
import com.tcs.mServicesBO.FFA_CONTACT_DETAILS;
import com.tcs.mServicesBO.FFA_SERVICE_REQUEST;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
public class TabActivityScreen extends TabActivity {
private static DBAdapter dbAdapter;
private static Context context;
private static InteractiveAdapter interactiveAdapter;
private static ListView assignedListView;
/** Called when the activity is first created. */
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabactivityscreen);
ArrayList<FFA_SERVICE_REQUEST> ffa_Service_Requests=(ArrayList<FFA_SERVICE_REQUEST>) this.getIntent().getExtras().get("ffa_service_RequestBO");
ArrayList<FFA_CONTACT_DETAILS> ffa_Contact_Details=(ArrayList<FFA_CONTACT_DETAILS>) this.getIntent().getExtras().get("ffa_Contact_DetailsBO");
/*
* Tab Related Code
*
*/
Resources res = getResources(); // Resource object to get Drawables
final TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
final Intent assignedIntent; // Reusable Intent for each tab
final Intent acceptedIntent;
final Intent returnedIntent;
final Intent completedIntent;
// Create an Intent to launch an Activity for the tab (to be reused)
assignedIntent = new Intent().setClass(this, AssignedActivity.class);
assignedIntent.putExtra("ffa_service_RequestBO", ffa_Service_Requests);
assignedIntent.putExtra("ffa_Contact_DetailsBO", ffa_Contact_Details);
// Initialize a TabSpec for each tab and add it to the TabHost
/* spec = tabHost.newTabSpec("ASSIGNED").setIndicator("Assigned")
.setContent(assignedIntent);*/
spec = tabHost.newTabSpec("ASSIGNED").setIndicator("Assigned")
.setContent(R.id.assignedLin);
tabHost.addTab(spec);
acceptedIntent = new Intent().setClass(this, AcceptedActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
/* spec = tabHost.newTabSpec("ACCEPTED").setIndicator("Accepted")
.setContent(acceptedIntent);*/
spec = tabHost.newTabSpec("ACCEPTED").setIndicator("Accepted")
.setContent(R.id.acceptedTbl);
tabHost.addTab(spec);
returnedIntent = new Intent().setClass(this, ReturnedActivity.class);
spec = tabHost.newTabSpec("RETURNED").setIndicator("Returned")
.setContent(returnedIntent);
tabHost.addTab(spec);
completedIntent = new Intent().setClass(this, CompletedActivity.class);
spec = tabHost.newTabSpec("COMPLETED").setIndicator("Completed")
.setContent(completedIntent);
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height=75;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height=75;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height=75;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().height=75;
tabHost.setCurrentTab(0);
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabId){
if("ASSIGNED".equals(tabId)){
tabHost.setCurrentTabByTag(tabId);
}else if("ACCEPTED".equals(tabId)){
tabHost.setCurrentTabByTag(tabId);
}
}
});
}
}
我就像标签的许多活动一样。虽然试图让它成为观点得到一些问题。请帮忙
答案 0 :(得分:1)
TabContent没有将assignedLin作为其子项。在FrameLayout中包含assignedLin。现在不是。