안드로이드 개발 질문/답변
(글 수 45,052)
Activity의 onCreate() 내에서 setContentView 이후에 직접 작성한 CustomView를
findViewById() 로 찾아내어 제어를 하려고 하나 null 값이 들어오고 있습니다.
당최 어디가 잘못된 것인지 고심고심 하다가 질문 올립니다.
능력자분들~! 답변 좀 부탁드립니다.
(SDK 1.6 Donut)
main.xml
<?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" > <TextView android:layout_width="fill_parent" android:layout_height="10dp" android:text="@string/hello" /> <com.test.MapCanvas android:id="@+id/map_canvas" android:layout_width="fill_parent" android:layout_height="100dp" android:focusable="true" android:clickable="true" /> </LinearLayout>
MapCanvas.java
package com.test; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.View; public class MapCanvas extends View { // ... public MapCanvas(Context context) { super(context); initialize(); } public MapCanvas(Context context, AttributeSet attrs) { super(context); initialize(); } private void initialize() { // ... } @Override protected void onDraw(Canvas canvas) { // ... } }
Activity.java
package com.test; import android.app.Activity; import android.os.Bundle; import com.test.MapCanvas; public class Test113 extends Activity { /** Called when the activity is first created. */ private MapCanvas mapCanvas; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapCanvas = (MapCanvas)this.findViewById(R.id.map_canvas); // null 값이 들어가는 곳. } }