startActivityForResult °ª ÁÖ°í¹Þ±â |
|
|
|
8³â Àü |
1. onCreate ¹Ù·Î¾Æ·¡ µðÆÄÀÎ
private static final int REQ_CODE_SELECT_TEMPLATE = 1;
2. ¹öÆ° À̺¥Æ® ÇÏÀ§¿¡ ¼Ò½º»ðÀÔ.( ³ª´Â ¹öÆ°À¸·Î ¾×¼ÇÀ̺¥Æ®¸¦ ÃëÇß´Ù.)
public void [¹öÆ° À̺¥Æ® Á¤ÀÇ](View _view)
{
Intent intent = new Intent(this, [°ª ÁÖ°í¹ÞÀ» Ŭ·¡½º].class);
startActivityForResult(intent, REQ_CODE_SELECT_TEMPLATE);
}
3. onActivityResult Á¤ÀÇ
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// ÅÛÇø´ ¼±Åà ¾×ƼºñƼÀÏ°æ¿ì
if(requestCode == REQ_CODE_SELECT_TEMPLATE)
{
// ¾×ƼºñƼ°¡ Á¤»óÀûÀ¸·Î °ªÀ» ó¸®ÇÏ°í
if(resultCode ==RESULT_OK)
{
int nSelectedTemplate = data.getIntExtra("[ÆĶó¹ÌÅÍ °ª String]", -1);
if(nSelectedTemplate != -1)
{
mbtTemplate.setText("selected :"+nSelectedTemplate); // µÇ ¹ÞÀº String°ª ºÎ¸ð ¿¢Æ¼ºñƼ¿¡¼ setText (Ex)button)
}
}
else
{
// ¾×ƼºñƼ µ¥ÀÌÅÍ ÁÖ°í ¹Þ±â ¿À·ù
}
}
}
4. ÀÚ½Ä ¿¢Æ¼ºñƼ¿¡¼ inputExtra¸¦ »ç¿ëÇÑ ¸Þ¼Òµå »ý¼º
private void terminateActivity()
{
Intent intent = getIntent(); // ÀÌ ¾×ƼºñƼ¸¦ ½ÃÀÛÇÏ°Ô ÇÑ ÀÎÅÙÆ®¸¦ È£Ãâ
intent.putExtra("[ÆĶó¹ÌÅÍ°ª]", mnSelectedIndex);
setResult(RESULT_OK, intent); // Ãß°¡ Á¤º¸¸¦ ³ÖÀº ÈÄ ´Ù½Ã ÀÎÅÙÆ®¸¦ ¹ÝȯÇÕ´Ï´Ù.
//setResult(RESULT_CANCELED, intent);
finish();
}
5. position°ªÀ» mnSelectedIndex¿¡ ÀÔ·Â (º»¹®¿¡¼´Â GridView¸¦ ¹Þ¾Æ¿È, [GridView].OnItemClick)
@Override
public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
mnSelectedIndex = position;
terminateActivity();
}
|
|
̵̧ : 275 |
̵̧
¸ñ·Ï
|
|