三星总是返回 null,但它适用于 HTC - findViewbyId

发布于 2024-12-23 14:36:43 字数 532 浏览 2 评论 0原文

我有一个奇怪的问题,非常奇怪。在 xml 中,我有

    <Button
        android:id="@+id/btnV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="10dp"
        android:background="@drawable/selector_app_update">
    </Button>

,在代码中

btnV = (Button) findViewById(R.id.btnV);

,在 HTC 上它可以工作,但在三星上我每次都得到 null。有人有类似的问题吗?我清理并重新启动了项目和 Eclipse,但什么也没有。

I have strange problem, very strange. In xml I have

    <Button
        android:id="@+id/btnV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:layout_marginRight="10dp"
        android:background="@drawable/selector_app_update">
    </Button>

and in code

btnV = (Button) findViewById(R.id.btnV);

and on HTC it works but on Samsung I am getting null every time. Did anyone have similar problem ? I cleaned and restarted project and eclipse but nothing .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此刻的回忆 2024-12-30 14:36:43

问题可能是您的自定义背景可绘制。

这些设备的屏幕尺寸或 DPI 是否不同?
您在drawable-ldpi和drawable-hdpi中是否有不同的drawable,但在标准drawable文件夹中没有?

Problem could be your custom background drawable.

Do these devices have different screen sizes or DPI?
Do you have different drawables in drawable-ldpi and drawable-hdpi but not in the standard drawable folder?

浮光之海 2024-12-30 14:36:43

这听起来确实很奇怪,通常我会要求您清理项目,甚至可能重新启动 Eclipse,但从表面上看,您已经尝试过了。

重命名 Button 视图的 ID 怎么样?你尝试过吗?

您能否显示初始化布局和 Button 的代码部分?

This does sound very strange and normally I would have asked you to clean the project and possibly even restart Eclipse, but by the looks of it, you've already tried that.

How about renaming the ID of your Button view? Have you tried that?

Can you please show the part of your code where you initialize the layout and Button?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文