Android: How to make a button on the candidate view in softkeyboard?

I want to make buttonView inside a button, but

you see log cat:

enter image description here

please share the code

My code is 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;
    }

I want to do this:

enter image description here

Layout 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>

Thanks for the promotion

+4
source share
1 answer

See this line

LinearLayout ll = (LinearLayout) wordBar.findViewById(R.id.words);

You create a TextView in LinearLayout

 <TextView
        android:id="@+id/words"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

R.id.words is a textview

Decision

Add an identifier to your LinearLayout

Example :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>

And use this id

 LinearLayout ll = (LinearLayout) wordBar.findViewById(R.id.wordsLayout);
+2
source

Source: https://habr.com/ru/post/1606351/


All Articles