Why does my TabWidget give me a source not found error?
I am creating a iphone like menu bar on the bottom of my screen. It is designed as a tab page and whenever I call it, it gets stuck on the first line
tabHost.addTab(createTab(Settings.class, "Settings", "Settings",
R.drawable.settingsicon));
The page Settings.java works normally and I checked my manifest to see if all my activities are added in there. I can't figure out why I keep getting this error. I tried using a try/catch block but it wouldn't allow me because it says it will never have an error, so I can't see my LogCat for the exact error. Here is my code. TabPage.java
public class TabPage extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_layout);
final TabHost tabHost = (TabHost) getTabHost();
tabHost.addTab(createTab(Settings.class, "Settings", "Settings",
R.drawable.settingsicon));
tabHost.addTab(createTab(ImTracking.class, "I\'m Tracking",
"I\'m Tracking", R.drawable.mapbutton));
tabHost.addTab(createTab(TrackingMe.class, "Tracking Me",
"Tracking Me", R.drawable.friends));
tabHost.addTab(createTab(ImTracking.class,"I\'m Tracking","I\'m Tracking",R.drawable.like));
tabHost.addTab(createTab(ImTracking.class,"I\'m Tracking","I\'m Tracking",R.drawable.help));
tabHost.setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(4).getLayoutParams().width = 85;
}
private TabSpec createTab(final Class<?> intentClass, final String tag,
final String title, final int drawable)
{
final Intent intent = new Intent().setClass(this, intentClass);
final View tab = LayoutInflater.from(getTabHost().getContext()).
inflate(R.layout.tab, null);
((TextView)tab.findViewById(R.id.tab_text)).setText(title);
((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);
return getTabHost().newTabSpec(tag).setIndicator(tab).setContent(intent);
}
}
tab.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center" >
<ImageView android:id="@+id/tab_icon" android:layout_width="30dp"
android:layout_height="30dp" android:scaleType="fitCenter" />
<TextView android:id="@+id/tab_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:singleLine="true"
android:textStyle="bold" android:gravity="center_horizontal"
android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee"
android:textColor="#000000" />
</LinearLayout>
tab_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentBottom="true">
<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">
<HorizontalScrollView android:scrollbars="none"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="@android:id/tabs"
开发者_JS百科 android:layout_alignParentBottom="true"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
My Settings page works normally when called, it is shown here to see if theres something I overlooked. Settings.java
public class Settings extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.settings);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_4);
Button deleteAccount = (Button) findViewById(R.id.btnDeleteAccount);
deleteAccount.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
new AlertDialog.Builder(Settings.this)
// fix this later
.setTitle(
getResources().getString(
R.string.deleteaccountquestion))
.setMessage(
getResources().getString(
R.string.selectingyeswill))
.setPositiveButton("No", null)
.setNegativeButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0,
int arg1) {
SharedPreferences prefs = getSharedPreferences(
"Settings", 0);
SharedPreferences.Editor editor = prefs
.edit();
editor.putBoolean(
"ImTrackingDontRemind", false);
editor.putBoolean("ACTIVATED", false);
editor.putString("ID", "");
editor.commit();
}
}).show();
}
});
Button MORETESTS=(Button) findViewById(R.id.btnHistory);
MORETESTS.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent tabpage=new Intent("com.cellphone.TABPAGE");
startActivity(tabpage);
}
});
TextView myname=(TextView) findViewById(R.id.tVName);
SharedPreferences prefs = getSharedPreferences("Settings", 0);
final String me = prefs.getString("MyName", "");
myname.setText(me);
Button reEnableHelp = (Button) findViewById(R.id.btnRenableHelpScreen);
reEnableHelp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO
// Auto-generated
// method stub
SharedPreferences prefs = getSharedPreferences("Settings", 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("ImTrackingDontRemind", false);
editor.commit();
};
});
}
}
Thanks!
精彩评论