【发布时间】:2016-06-01 04:04:43
【问题描述】:
您好,如何将片段中的两个参数传递给活动?我试图这样做,但我做不到。 我只得到了 TextView editRef 中的 ref,但 TextView et_login 是空的
public class ResultFragmentC extends Fragment implements ListView.OnItemClickListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootview = inflater.inflate(R.layout.fragment_result, container, false);
et_login = (TextView) rootview.findViewById(R.id.et_login);
Intent intent = getActivity().getIntent();
String log = intent.getStringExtra("login");
et_login.setText(log);
......
}
......
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity().getApplicationContext(), ViewResult.class);
HashMap<String, String> map = (HashMap) parent.getItemAtPosition(position);
String tid = map.get("ref");
intent.putExtra("ref", tid);
String tid2 = map.get("log");
intent.putExtra("log", tid2);
startActivity(intent);
}
ViewResult.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_result);
Intent intent = getIntent();
layout=(LinearLayout) findViewById(R.id.layout);
String ref2 = intent.getStringExtra("ref");
et_login = (TextView) findViewById(R.id.et_login);
String log = intent.getStringExtra("log");
et_login.setText(log);
editRef = (TextView) findViewById(R.id.editRef);
editRef.setText(ref2);
}
【问题讨论】:
-
这应该可以了,你确定你放的时候log不为空或者null吗?
-
@cricket_007 是两个。对不起
-
@cyroxis 是的,它不是空的
-
我有一个登录表单。所以我想在所有片段和活动中显示登录。在第一个片段中,我有一个带有登录名的列表视图,但是当我单击列表视图时,活动中没有显示登录名
标签: android