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

다른 버튼 같은 명령문으로 실행시키는 질문이요

0 추천
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.menu_activity2);

  ImageButton image01 = (ImageButton) findViewById(R.id.t1);
  ImageButton image02 = (ImageButton) findViewById(R.id.t2);
  ImageButton image03 = (ImageButton) findViewById(R.id.t3);
  ImageButton image04 = (ImageButton) findViewById(R.id.t4);
  
  image01.setOnClickListener(this);
  image02.setOnClickListener(this);
  image03.setOnClickListener(this);
  image04.setOnClickListener(this);


 } 



.
.
.
.

public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v != null){
  Intent myIntent = new Intent(getApplicationContext(), CameraActivity2.class);
  startActivity(myIntent);
  }
  
  else
   return;
  
 }

각각 다른 버튼인데

 

클릭했을 때 같은 명령으로 하고 싶어요!

 

 

이렇게 했는데 첫번째만 실행이 되고 나머지는 안먹히더라구요.

익명사용자 님이 2014년 8월 23일 질문

1개의 답변

0 추천
@Override
	public void onClick(View v) {
		switch (v.getId()) {
		default:
			Intent myIntent = new Intent(this, CameraActivity2.class);
                        startActivity(myIntent);
		}
	}

 

이렇게 한번 해보세요

ontwikkelaar (2,260 포인트) 님이 2014년 8월 24일 답변
...