为什么我的TabWidget给我一个未找到源错误?

时间:2011-08-18 20:03:35

标签: android tabs

我正在屏幕底部创建一个类似iphone的菜单栏。它被设计为标签页,每当我调用它时,它就会卡在第一行

tabHost.addTab(createTab(Settings.class, "Settings", "Settings",
                R.drawable.settingsicon));  

页面Settings.java正常工作,我检查了我的清单,看看我的所有活动是否都添加到那里。我无法弄清楚为什么我一直收到这个错误。我尝试使用try / catch块,但它不允许我,因为它说它永远不会有错误,所以我无法看到我的LogCat确切的错误。这是我的代码。 TabPage.java

public class TabPage扩展了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" 
                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> 

我的设置页面在调用时正常工作,此处显示是否有我忽略的内容。 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();
        };
    });

}

}

谢谢!

0 个答案:

没有答案