Android пользовательский просмотр, заставляющий усилия закрыть
-
10-10-2019 - |
Вопрос
У меня есть пользовательский просмотр в src> myproject.test> Homeview
В моем основном макете XML у меня есть следующее:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<myproject.test.HomeView
android:id="@+id/home_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</myproject.test.HomeView>
</LinearLayout>
В домашней активности у меня есть такой звонок в методе Oncreate.
setContentView(R.layout.main);
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);
Сила приложения закрыто, когда вызывается метод SetContentView. Кажется, что мой главный XML не прав.
Любые идеи?
Решение
Вы имеете в виду, что это не добраться до
HomeView mHomeView = (HomeView) this.findViewById(R.id.home_view);
и сбой на линии перед ней?
Проверьте, является ли ваш конструктор
HomeView(final Context context, final AttributeSet attrs){
super(context, attrs);
и не
HomeView(final Context context){
super(context);
вам нужен атрибута
Другие советы
Проверьте конструкторы, которые реализует ваш Homeview:
public HomeView(Context context, AttributeSet atts) {
super(context, atts);
}
<LinearLayout xmlns:android =
http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
Ни у одного из моих макетов нет @+id
. Анкет Может вам следует настроить представление на home_root
. Анкет Проверьте с вами R.Java для названия макета или попробуйте
setContentView(R.layout.home_root);
Не связан с StackOverflow