android–findViewById未定义

android–findViewById未定义,第1张

概述Eclipse将findViewById(int)标记为未定义;它为getResources()做了同样的事情,但是我能够通过调用context.getResources()来解决这个问题(如下所示),并且似乎找不到类似的findViewById解决方法.这是代码:packagecom.myapp.android.MyWidget;importandroid.appwidget.AppWidgetP

Eclipse将findVIEwByID(int)标记为未定义;它为getResources()做了同样的事情,但是我能够通过调用context.getResources()来解决这个问题(如下所示),并且似乎找不到类似的findVIEwByID解决方法.这是代码:

package com.myapp.androID.MyWidget;import androID.appWidget.appwidgetprovider;import androID.appWidget.AppWidgetManager;import androID.content.Context;import androID.content.Componentname;import androID.content.pm.PackageManager;import androID.content.res.Resources;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.RemoteVIEws;import androID.Widget.button;import androID.os.Bundle;public class MyWidget extends appwidgetprovider { private static String[] states; @OverrIDe public voID onEnabled(Context context) {  final button button = (button) findVIEwByID(R.ID.Widget_state_button);  states = context.getResources().getStringArray(R.array.states); }

我需要为findVIEwByID导入另一个包吗?提前致谢.

解决方法:

当您使用AppWidgets时,代码的工作方式会有所不同.基本上你需要使用RemoteVIEw而不是传统的buttons和findVIEwByIDs.有关如何编写AppWidgets的链接,请参阅此similar question.特别是developer.com教程的两个链接.

总结

以上是内存溢出为你收集整理的android – findViewById未定义全部内容,希望文章能够帮你解决android – findViewById未定义所遇到的程序开发问题。

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

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

原文地址:https://www.54852.com/web/1118628.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存