我在一个片段中有一个 Bundle,它将一个字符串传递给另一个片段。此字符串需要在文本视图中设置文本,而我的方法不起作用。我不知道为什么,但我所有的其他字符串都通过了。
请看看我的代码,让我知道我有什么问题 - 我不明白......
从:
public void onClick(View v) {
Bundle args = new Bundle();
FragmentManager fm = getFragmentManager();
final FragmentTransaction vcFT = fm.beginTransaction();
vcFT.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out, R.anim.hyperspace_in, R.anim.slide_out);
switch (v.getId()) {
case R.id.regulatoryBtn :
String keyDiscriptionTitle = "Regulatory Guidance Library (RGL)";
args.putString("KEY_DISCRIPTION_TITLE", keyDiscriptionTitle);
RegulatoryDiscription rd = new RegulatoryDiscription();
vcFT.replace(R.id.viewContainer, rd).addToBackStack(null).commit();
rd.setArguments(args);
break;
. . .
}
到:
public class RegulatoryDiscription extends Fragment {
Bundle args = new Bundle();
String DNS = "http://192.168.1.17/";
String KEY_DISCRIPTION_TITLE = "KEY_DISCRIPTION_TITLE";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.discription_view, container, false);
TextView title = (TextView) view.findViewById(R.id.discriptionTitle);
String keyDiscriptionTitle = args.getString(KEY_DISCRIPTION_TITLE);
title.setText(keyDiscriptionTitle);
return view;
}
. . .
}