액티비티 클래스 내에 SurfaceView
을 확장하는 클래스를 내부 클래스로 가질 수 있습니까? 이런 식으로 뭔가 :내부 클래스의 캔버스, 안드로이드
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.android.iiProject.Presentation.DrawCanvas
android:id="@+id/SurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Presentation
이 활동 클래스입니다
하고 DrawCanvas
는 SurfaceView
를 확장하는 클래스이며, DrawCanvas
객체는 Presentation
활동 내에서 호출됩니다.
Presentation
액티비티 내에서 사용할 수있는 메서드와 변수에 액세스 할 수 있기를 원하기 때문에이 방법이 필요합니다. 다른 클래스의 메서드 및 변수에 접근하기 위해 정적으로 선언하고 싶지는 않습니다. 추가 문제가 많이 ...! 이 방법은 다음과 같이
1 modifying an existing view type, 지점을 참조하십시오. –
답장을 보내 주셔서 감사합니다. 하지만 DrawCanvas (내부 클래스)를 참조 할 때 classCastException이 발생합니다. XML의 일반 객체 "보기"로 선언 되었기 때문에 DrawCanvas로 캐스팅 할 수 없어야합니까?! 문제가있는 문장 : DrawCanvas mycanvas = (DrawCanvas) findViewById (R.id.SurfaceView); – NZal