다중 액티비티 예제
MainActivity.java
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp);
}
public void mOnClick(View v)
{
Intent intent = new Intent(this, SubActivity.class);
switch(v.getId())
{
case R.id.Seoul:
intent.putExtra("buttonName", "Seoul");
startActivity(intent);
break;
case R.id.Busan:
intent.putExtra("buttonName", "Busan");
startActivity(intent);
break;
}
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
}
SubActivity.java
public class SubActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temp2);
Intent intent = getIntent();
String str = intent.getStringExtra("buttonName");
if( str != null)
{
if( str.equals("Seoul"))
{
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.seoul);
}
else if( str.equals("Busan"))
{
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.busan);
}
}
}
public void mOnClick(View v)
{
}
}
'Programming > Android' 카테고리의 다른 글
테이블 동적 생성 (0) | 2013.03.23 |
---|---|
TabActivity 사용법 (0) | 2013.03.23 |
안드로이드 레이아웃 예제 (0) | 2013.03.16 |
안드로이드 실습 (0) | 2013.03.09 |
Intent 활용하기 (0) | 2013.03.08 |