
我想在候选内部按钮,但是
你看日志猫:
请分享代码
我的守则
SoftKeyboard.java
@OverrIDe public VIEw onCreateCandIDatesVIEw() { LayoutInflater li = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); VIEw wordbar = li.inflate(R.layout.wordbar, null); linearLayout ll = (linearLayout) wordbar.findVIEwByID(R.ID.words); button btn = (button) wordbar.findVIEwByID(R.ID.button1); btn.setonClickListener(this); mCandIDateVIEw = new CandIDateVIEw(this); mCandIDateVIEw.setService(this); setCandIDatesVIEwShown(true); mCandIDateVIEw.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); ll.addVIEw(mCandIDateVIEw); return wordbar; }我想这样做:
布局wordbar.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/words" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" > <button androID:ID="@+ID/button1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="button" /></linearLayout>谢谢你提前
解决方法:
看到这一行
linearLayout ll = (linearLayout) wordbar.findVIEwByID(R.ID.words);您正在将TextVIEw转换为linearLayout
<TextVIEw androID:ID="@+ID/words" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" />R.ID.words是一个TextVIEw
解
将ID添加到linearLayout
示例:androID:ID =“@ ID / wordsLayout”
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:ID="@+ID/wordsLayout" androID:layout_height="wrap_content" androID:orIEntation="horizontal" > <TextVIEw androID:ID="@+ID/words" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" /> <button androID:ID="@+ID/button1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="button" /></linearLayout>并使用该ID
linearLayout ll = (linearLayout) wordbar.findVIEwByID(R.ID.wordsLayout); 总结 以上是内存溢出为你收集整理的Android:如何在软键盘中的候选视图上创建按钮?全部内容,希望文章能够帮你解决Android:如何在软键盘中的候选视图上创建按钮?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)