TabbarActivity 片段未调用到 onActivityResult
TabbarActivity fragment not called to onActivityResult
我正在使用 tabbaractivity 并且其中一个选项卡包含 listView
我想在每次添加对象时更新 listView。
添加对象我从新 activity
我想要的是什么时候 activity 将关闭 listView 将通过使用更新
adapter.notifydatachanged
在我的 activity 中包含选项卡
if (id == R.id.addButton) {
Intent intent = new Intent(rootViewTabBarActivity.this, addPictureActivity.class);
startActivityForResult(intent,101);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
在片段中(选项卡之一)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 101) && (resultCode == Activity.RESULT_OK))
adapter.notifyDataSetChanged();
}
和创建对象并将其保存到数据库的activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAM_REQUEST) {
Bitmap btmp = (Bitmap)data.getExtras().get("data");
takenPhoto.setImageBitmap(btmp);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
setResult(Activity.RESULT_OK);
}
谢谢
fragment not called to onActivityResult
您错过了将数据从 Activity 传递到片段
在Activity中,你的代码应该是这样的:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
YourFragment fragment = getFragment();
if (fragment != null) {
// Pass data to Fragment
fragment.onActivityResult(requestCode, resultCode, data);
}
}
}
public YourFragment getFragment() {
// You can find your fragment (by tag/ by id) here depends on your layout
}
我正在使用 tabbaractivity 并且其中一个选项卡包含 listView 我想在每次添加对象时更新 listView。 添加对象我从新 activity 我想要的是什么时候 activity 将关闭 listView 将通过使用更新 adapter.notifydatachanged
在我的 activity 中包含选项卡
if (id == R.id.addButton) {
Intent intent = new Intent(rootViewTabBarActivity.this, addPictureActivity.class);
startActivityForResult(intent,101);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
在片段中(选项卡之一)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 101) && (resultCode == Activity.RESULT_OK))
adapter.notifyDataSetChanged();
}
和创建对象并将其保存到数据库的activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAM_REQUEST) {
Bitmap btmp = (Bitmap)data.getExtras().get("data");
takenPhoto.setImageBitmap(btmp);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
setResult(Activity.RESULT_OK);
}
谢谢
fragment not called to onActivityResult
您错过了将数据从 Activity 传递到片段 在Activity中,你的代码应该是这样的:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
YourFragment fragment = getFragment();
if (fragment != null) {
// Pass data to Fragment
fragment.onActivityResult(requestCode, resultCode, data);
}
}
}
public YourFragment getFragment() {
// You can find your fragment (by tag/ by id) here depends on your layout
}