I followed the example in the Android website to create a tab activity with multiple activities. Now I am trying to have it as Single activity and multiple views. I am getting the following exception
Java.lang.RuntimeException : Could not create tab content because could not find the view by id
This is my layout file.
<?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>
this is my java file
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);
}
}
});
}
}
I had it like many activities for the tabs. While trying to make it as views getting some problem. Pls help
TabContent does not have assignedLin as its child. Include assignedLin in FrameLayout. Right now it is not.