android自定义控件是一个 内部类 如何在xml中引用,在xml文件中引用内部类笔记

场景:自己在activity中使用内部类MyAutoCompleteTextView继承了AutoCompleteTextView重写其中一个方法,这个类只在这个activity的布局文件中使用,没有必要单独写一个类出来,现在想要在xml文件中使用这个view

参考文章:http://titanseason.iteye.com/blog/1831185

使用上面文章里面的方法可以在xml中引用,但是在findViewById找到以后不能强转为AutoCompleteTextView,报错。

解决方法:将View修改为AutoCompleteTextView。

布局文件如下:

class="com.smb.merchant.activity.LoginActivity$MyAutoCompleteTextView"

android:id="@+id/et_login_name"

style="@style/tm_text_large"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:layout_marginLeft="@dimen/tm_layout_margin_defalut"

android:layout_weight="1.0"

android:background="@null"

android:hint="@string/tm_str_account_name_hint"

android:imeOptions="actionNext"

android:textColorHint="@color/text_color_login_hint"

android:dropDownAnchor="@id/layout_username" />另:开始我在写class里面的包名的时候是class="com.smb.merchant.activity$MyAutoCompleteTextView",没有写全,少了.LoginActivity这个类名,可是我运行起来没有问题,不知道为什么,好神奇。

总结

以上是编程之家为你收集整理的在xml文件中引用内部类笔记全部内容,希望文章能够帮你解决在xml文件中引用内部类笔记所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值