0

I would like to show two views in a service context. One is a TextView, and the other is a class that I have developed extending the basic View class.
prompt.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mtPrompt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/background_dark"
    android:text="@string/demoString"
    android:textColor="@android:color/white"
    android:minLines="2"
    android:textSize="25dp" >
</TextView>

and input.xml:

<com.xxx.ime.sssView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inputView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/translucent_gray"
    android:cacheColorHint="@null" >

</com.xxx.ime.sssView>

in my onInitializeInterface() implementation I inflate them as follows:

 sssView sv = 
        (sssView) getLayoutInflater().inflate(R.layout.input, null);
 TextView tv = 
        (TextView) getLayoutInflater().inflate(R.layout.prompt, null);

I see the sssView, but not the TextView. Any ideas why?

Aharon Manne
  • 712
  • 3
  • 11
  • 34
  • do you set both as setContentView? – Simon Dorociak Jun 26 '12 at 08:42
  • No, as the example I was working from (SoftKeyboard) did not call setContentView(). I would have to deduce the activity in order to make that call, and that doesn't sound right. – Aharon Manne Jun 26 '12 at 14:47
  • Continuing to look into this after a break...
    Since one view is visible, I decided to use a ViewGroup (LinearLayout) to hold both of my views. In this case, I get an IllegalStateException thrown in InputMethodService.setInputView(), a function which I did not override. The error message says "The specified child already has a parent". I take it that this means that setInputView is tring to re-attach the child views in my LinearLayout. Can (and should) I try to prevent this by overriding setInputView. I guess I'll try and see what happens.
    – Aharon Manne Jul 11 '12 at 08:05
  • Overriding setInputView with a do-nothing function avoids the exception, but makes my IME completely invisible. What if I remove the child views, then call super.setInputView? – Aharon Manne Jul 11 '12 at 09:46
  • That didn't help either, returning to the version with two separate views, each of which is inflated independantly. In the Softkeyboard example, there is a view for the keyboard, and a Canvas which seems to contain all of the candidate stuff (I couldn't find a view). It should be possible to inflate two UI entities, in any event. – Aharon Manne Jul 12 '12 at 09:13

1 Answers1

0

This isn't quite an answer, but it is a solution. Rather than having two separate views, all I needed to do was inherit my sssView from TextView rather than view. Then I inflated the one view, and placed my text where I want it using gravity.

Aharon Manne
  • 712
  • 3
  • 11
  • 34