마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

스피너로 MyGraphicView의 비트맵 이미지 변경하기

0 추천
스피너를 사용해서 이미지 뷰가 아닌 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();
        }
    }
}
익명사용자 님이 2016년 11월 7일 질문

1개의 답변

0 추천
sname 값을 변경하시고 어댑터에서 invalidate를 호출하세요
익명사용자 님이 2016년 11월 7일 답변
...