我能够在onActivityResult()中获得结果,我可以在日志中看到该结果,但是当我尝试将其设置为textView时,什么也没发生。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case GET_DATA:
if (resultCode == RESULT_OK) {
UserLogs.e("success");
String id = data.getStringExtra("id");
UserLogs.e(id + "%%%%%%%%%%%%%%%%%%%%%%%");
UserLogs.e(tvName.getText().toString());
tvId.setText(id);
}
break;
}
UserLogs.e(tvName.getText()。toString()); 显示文本视图的值。
编辑: 替换片段并从另一个片段获取结果
fragment = new FragmentB();
fragment.setTargetFragment(FragmentA.this, GET_DATA);
Bundle bundle = new Bundle();
bundle .putString("position", "fr");
fragment.setArguments(bundle );
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment, "frag_b").addToBackStack(null).commit();