Я пытаюсь создать Android-клавиатуру, прямо сейчас я хочу, чтобы она просто раздувалась, то есть show, linearlayout из main.xml
Здесь java файл
package keyboard.rob.com;
import ...
public class zyz extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
private KeyboardView mInputView;
@Override public void onCreate() {
super.onCreate();
}
@Override public View onCreateInputView() {
mInputView = (KeyboardView) getLayoutInflater().inflate(R.layout.main, null);
return mInputView;
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:id="@+id/LL_whole" android:orientation="vertical" android:clickable="false">
<LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@layout/backrep" android:layout_gravity="center" android:id="@+id/LL_total" android:orientation="vertical" android:layout_height="wrap_content">
<LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@drawable/spell_frame" android:layout_marginBottom="10px" android:layout_marginTop="5px" android:layout_gravity="center" android:id="@+id/LL_spell" android:paddingLeft="10px">
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center" android:layout_width="wrap_content" android:id="@+id/LLrow1">
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" android:id="@+id/LLrow2"></LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" android:id="@+id/LLrow3"></LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" android:id="@+id/LLrow4">
</LinearLayout>
</LinearLayout>
</LinearLayout>
и ошибка, с которой он падает:
08-29 20:21:28.128: ERROR/AndroidRuntime(10227): java.lang.ClassCastException: android.widget.LinearLayout
Есть идеи? Благодарю!
попробуйте ниже код..
package keyboard.rob.com;
import ...
public class TotalKeyboard extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {
private LinearLayout mInputView;
@Override public void onCreate() {
super.onCreate();
}
@Override public View onCreateInputView() {
mInputView = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null);
return mInputView;
}
}
Вы создаете свой макет, который в основном представляет собой LinearLayout
, для KeyboardView
. Это дает исключение класса. Поскольку onCreateInputView()
возвращает View
, для удаления броска достаточно его удалить. LayoutInflater.inflate()
уже возвращает View
. Не нужно бросать его ни к чему. (LinearLayout
расширяет класс View
, поэтому он действителен в этом случае)
Поэтому попробуйте изменить
mInputView = (KeyboardView) getLayoutInflater().inflate(R.layout.main, null);
в
mInputView = getLayoutInflater().inflate(R.layout.main, null);
В качестве альтернативы вы можете LinearLayout
его к LinearLayout
, но здесь это не так.