java-在android中设置简单的自定义标签

java-在android中设置简单的自定义标签,第1张

概述我正在尝试在android中生成自定义tabViewAndroidTabRestaurantDescListView.javapublicclassAndroidTabRestaurantDescListViewextendsTabActivity{//TabSpecNamesprivatestaticfinalStringINBOX_SPEC="Rating";privatestaticfinalSt

我正在尝试在android中生成自定义tabVIEw

AndroidTabRestaurantDescListVIEw.java

public class AndroIDTabRestaurantDescListVIEw extends tabactivity {    // TabSpec names        private static final String INBox_SPEC = "rating";        private static final String OUTBox_SPEC = "Price";        private static final String PROfile_SPEC = "distance";        private TabHost Photos;        @OverrIDe        public voID onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentVIEw(R.layout.main);            Photos=(TabHost) findVIEwByID(R.ID.Photobutton);             TabHost tabHost = getTabHost();            Photos.getTabWidget().setdivIDerDrawable(R.drawable.tab_divIDer);            // InBox Tab            TabSpec inBoxSpec = tabHost.newTabSpec(INBox_SPEC);            Intent inBoxIntent = new Intent(this, MainActivity.class);            inBoxSpec.setIndicator(INBox_SPEC);            // Tab Content            inBoxSpec.setContent(inBoxIntent);            // OutBox Tab            TabSpec PriceSpec = tabHost.newTabSpec(OUTBox_SPEC);            Intent PriceIntent = new Intent(this, PriceDescriptionActivity.class);            PriceSpec .setIndicator(OUTBox_SPEC);            PriceSpec.setContent(PriceIntent);            // Profile Tab            TabSpec distanceSpec = tabHost.newTabSpec(PROfile_SPEC);            Intent distanceIntent = new Intent(this, distancediscriptionActivity.class);            distanceSpec .setIndicator(PROfile_SPEC);             distanceSpec.setContent(distanceIntent);            // Adding all TabSpec to TabHost            tabHost.addTab(inBoxSpec);             tabHost.addTab(PriceSpec);             tabHost.addTab(distanceSpec);             //Set the current value tab to default first tab            tabHost.setCurrentTab(0);            //Setting custom height for the tabs            final int height = 45;            tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;            tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;            tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;            Photos.setonClickListener(new OnClickListener() {                public voID onClick(VIEw v) {                    Intent PhotoIntent = new Intent(AndroIDTabRestaurantDescListVIEw.this, AndroIDTabRestaurantDescImageListVIEw.class);                    startActivity(PhotoIntent);                             }            });        }}

日志::

10-03 18:49:34.710: D/AndroIDRuntime(561): Shutting down VM10-03 18:49:34.710: W/dalvikvm(561): threadID=1: thread exiting with uncaught exception (group=0x40015560)10-03 18:49:34.740: E/AndroIDRuntime(561): FATAL EXCEPTION: main10-03 18:49:34.740: E/AndroIDRuntime(561): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androIDbegin.Jsonparsetutorial/com.project.findmybuffet.AndroIDTabRestaurantDescListVIEw}: java.lang.classCastException: androID.Widget.button10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1647)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.ActivityThread.access00(ActivityThread.java:117)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:931)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.os.Handler.dispatchMessage(Handler.java:99)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.os.Looper.loop(Looper.java:123)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.ActivityThread.main(ActivityThread.java:3683)10-03 18:49:34.740: E/AndroIDRuntime(561):  at java.lang.reflect.Method.invokeNative(Native Method)10-03 18:49:34.740: E/AndroIDRuntime(561):  at java.lang.reflect.Method.invoke(Method.java:507)10-03 18:49:34.740: E/AndroIDRuntime(561):  at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)10-03 18:49:34.740: E/AndroIDRuntime(561):  at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:597)10-03 18:49:34.740: E/AndroIDRuntime(561):  at dalvik.system.NativeStart.main(Native Method)10-03 18:49:34.740: E/AndroIDRuntime(561): Caused by: java.lang.classCastException: androID.Widget.button10-03 18:49:34.740: E/AndroIDRuntime(561):  at com.project.findmybuffet.AndroIDTabRestaurantDescListVIEw.onCreate(AndroIDTabRestaurantDescListVIEw.java:27)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)10-03 18:49:34.740: E/AndroIDRuntime(561):  at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1611)10-03 18:49:34.740: E/AndroIDRuntime(561):  ... 11 more

解决此问题的任何输入
谢谢

解决方法:

问题在这一行:

Photos=(TabHost) findVIEwByID(R.ID.Photobutton);

我假设R.ID.Photobutton是一个button,并且您试图将其强制转换为TabHost,但是您不能这样做.

一切基本上都在您的日志中可见.这两行最相关:

10-03 18:49:34.740: E/AndroIDRuntime(561): Caused by: java.lang.classCastException: androID.Widget.button10-03 18:49:34.740: E/AndroIDRuntime(561):  at com.project.findmybuffet.AndroIDTabRestaurantDescListVIEw.onCreate(AndroIDTabRestaurantDescListVIEw.java:27)
总结

以上是内存溢出为你收集整理的java-在android中设置简单的自定义标签全部内容,希望文章能够帮你解决java-在android中设置简单的自定义标签所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1075871.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存