스피너를 사용해서 이미지 뷰가 아닌 MyGraphicView 클래스의 비트맵 이미지 소스를 변경해야 하는데요. 어떻게 해야 할까요?
public class MainActivity extends Activity {
MyGraphicView graphicView;
public static int SName = R.drawable.mov21;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("연습문제 11-6");
final String[] movie = { "쿵푸팬더", "짱구는 못말려", "아저씨", "아바타", "대부", "국가대표", "토이스토리3", "마당을 나온 암탉", "죽은 시인의 사회", "서유기" };
final Integer[] posterID = { R.drawable.mov21, R.drawable.mov22, R.drawable.mov23, R.drawable.mov24, R.drawable.mov25, R.drawable.mov26, R.drawable.mov27, R.drawable.mov28, R.drawable.mov29, R.drawable.mov30 };
final LinearLayout pictureLayout = (LinearLayout) findViewById(R.id.pictureLayout);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, movie);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
SName = posterID[arg2];
pictureLayout.
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
graphicView = (MyGraphicView) new MyGraphicView(this);
pictureLayout.addView(graphicView);
}
private static class MyGraphicView extends View {
public MyGraphicView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap picture = BitmapFactory.decodeResource(getResources(), SName);
int picX = (this.getWidth() - picture.getWidth()) / 2;
int picY = (this.getHeight() - picture.getHeight()) / 2;
canvas.drawBitmap(picture, picX, picY, null);
picture.recycle();
}
}
}