Android:如何在软键盘中的候选视图上创建按钮?

Android:如何在软键盘中的候选视图上创建按钮?,第1张

概述我想在候选内部按钮,但是你看日志猫:请分享代码我的守则SoftKeyboard.java@OverridepublicViewonCreateCandidatesView(){LayoutInflaterli=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);View

我想在候选内部按钮,但是

你看日志猫:

请分享代码

我的守则
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:如何在软键盘中的候选视图上创建按钮?所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存