클래스를 사용자 지정 클래스로 캐스팅합니다. 슬프게도이 두 가지가 나를 도왔다 고해도,이 질문은 시간이 흐르면서 Error referencing an inner class View in layout/main.xml과 Error referencing an inner class View in layout/main.xml으로 알려졌다. 내가 무엇을하려고하는지에 대한 빠른 배경.클래스를 사용자 지정 클래스로 캐스팅
사용자 지정 ListView, 적절하게 CustomListView 및 CustomButton이라는 사용자 지정 ImageView가 있습니다. xml 레이아웃을 사용하여 ListView 또는 ImageView 또는 사용자가 가지고있는 부모 레이아웃을 참조하는 XML 레이아웃을 설정하고 사용자 지정보기로 캐스팅합니다.
아래의 관련 코드와 스택 추적이 있습니다.
search_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#40FAEBD7">
<RelativeLayout android:id="@+id/pullDown_bar"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:tag="BLADEBEAT_PRO_SWIPEUP_PARENTLAYOUT"
android:background="@color/Black">
<View android:id="@+id/pullDown_inner_bar"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="13dp"
android:tag="BLADEBEAT_PRO_SWIPEUP_TOP_INNER_BAR"
android:focusableInTouchMode="true"
android:clickable="true"/>
</RelativeLayout>
<EditText android:id="@+id/search_bar"
android:hint="Type Here To Search Your Device"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pullDown_bar"
android:tag="BLADEBEAT_PRO_SWIPEUP_SEARCH_BAR"
android:focusableInTouchMode="true"/>
<RelativeLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/Cyan"
android:layout_below="@id/search_bar"
android:layout_alignParentLeft="true">
<ImageView
android:id="@+id/top_bar_left"
android:layout_width="50dp"
android:layout_height="match_parent"
android:background="@drawable/textmessage"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/bottom_bar"
android:tag="BLADEBEAT_PRO_SWIPEUP_BOTTOM_BAR"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:background="@color/Pink"
android:clickable="true">
<ImageView
android:id="@+id/bottom_bar_left"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"/>
<ImageView
android:id="@+id/bottom_bar_left_mid"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"/>
<ImageView
android:id="@+id/bottom_bar_mid"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"/>
<ImageView
android:id="@+id/bottom_bar_right_mid"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"/>
<ImageView
android:id="@+id/bottom_bar_right"
android:tag="BLADEBEAT_PRO_SWIPEUP_SETTINGS_BUTTON"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true"
android:background="@drawable/gear"
android:focusableInTouchMode="true"
android:clickable="true"/>
</RelativeLayout>
<ListView
android:id="@+id/result_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top_bar"
android:layout_above="@id/bottom_bar"
android:visibility="invisible"
android:tag="BLADEBEAT_PRO_SWIPEUP_RESULT_VIEW"
android:focusableInTouchMode="true"
android:clickable="true"/>
<RelativeLayout
android:id="@+id/content_filler"
android:tag="BLADEBEAT_PRO_SWIPEUP_CONTENT_FILLER"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/top_bar"
android:layout_above="@id/bottom_bar"
android:background="@color/Silver"
android:clickable="true"
android:focusableInTouchMode="true">
</RelativeLayout>
</RelativeLayout>
custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
<bladebeat.pro.utils.swipeup.GUI.CustomButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="Settings Button"
android:layout_gravity="center"/>
-->
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="bladebeat.pro.utils.swipeup.GUI.CustomButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
custom_list_view.xml 뷰가 팽창의 주요 코드
<?xml version="1.0" encoding="utf-8"?>
<bladebeat.pro.utils.swipeup.GUI.CustomListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</bladebeat.pro.utils.swipeup.GUI.CustomListView>
<!--
<bladebeat.pro.utils.swipeup.GUI.CustomListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
-->
<!--
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="bladebeat.pro.utils.swipeup.GUI.CustomListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
-->
포인트.
/**assume that layout is search_view inflated correctly, as the rest of the views called work just fine*/ lView = (CustomListView) layout.findViewById(R.id.result_view);
스택 트레이스는 : CustomListView은 ListView에 주변이 아닌 다른 방법을 확장하기 때문에
10-18 23:21:04.925: E/AndroidRuntime(2046): FATAL EXCEPTION: main
10-18 23:21:04.925: E/AndroidRuntime(2046): Process: bladebeat.pro.utils.swipeup, PID: 2046
10-18 23:21:04.925: E/AndroidRuntime(2046): java.lang.RuntimeException: Unable to start activity ComponentInfo{bladebeat.pro.utils.swipeup/bladebeat.pro.utils.swipeup.MainActivity}: java.lang.ClassCastException: android.widget.ListView cannot be cast to bladebeat.pro.utils.swipeup.GUI.CustomListView
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.os.Handler.dispatchMessage(Handler.java:102)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.os.Looper.loop(Looper.java:136)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-18 23:21:04.925: E/AndroidRuntime(2046): at java.lang.reflect.Method.invokeNative(Native Method)
10-18 23:21:04.925: E/AndroidRuntime(2046): at java.lang.reflect.Method.invoke(Method.java:515)
10-18 23:21:04.925: E/AndroidRuntime(2046): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-18 23:21:04.925: E/AndroidRuntime(2046): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-18 23:21:04.925: E/AndroidRuntime(2046): at dalvik.system.NativeStart.main(Native Method)
10-18 23:21:04.925: E/AndroidRuntime(2046): Caused by: java.lang.ClassCastException: android.widget.ListView cannot be cast to bladebeat.pro.utils.swipeup.GUI.CustomListView
10-18 23:21:04.925: E/AndroidRuntime(2046): at bladebeat.pro.utils.swipeup.MainActivity.createView(MainActivity.java:204)
10-18 23:21:04.925: E/AndroidRuntime(2046): at bladebeat.pro.utils.swipeup.MainActivity.loadActivity(MainActivity.java:147)
10-18 23:21:04.925: E/AndroidRuntime(2046): at bladebeat.pro.utils.swipeup.MainActivity.onCreate(MainActivity.java:134)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.Activity.performCreate(Activity.java:5231)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-18 23:21:04.925: E/AndroidRuntime(2046): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
10-18 23:21:04.925: E/AndroidRuntime(2046): ... 11 more
'result_view'는'ListView'이고 사용자 정의보기는 없습니다. 당신은 무엇을 기대 했습니까? – Smutje