1

我在一个活动上有很多按钮,它们都使用以下代码调用相同的活动

startActivityForResult()

结果被捕获

void onActivityResult(int requestCode, int resultCode, Intent data).

我如何知道按钮返回结果?

4

1 回答 1

6

change requestCode for every Button . You can use, for instance, as RequestCode the id of the button. When onActivityResult is called,

void onActivityResult(int requestCode, int resultCode, Intent data) {
  switch(requestCode) {
   case R.id.button1:
    break;
   }
}

you can switch on requestCode, ad case for the buttonId

于 2013-04-29T12:46:42.783 回答