我正在尝试将可点击的TextView中的数据传递到片段之间的EditText。现在,我可以在单击TextView时导航到另一个片段。这是CategoryFragment
的编码:
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(
getActivity().getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
HomeFragment fragment = new HomeFragment();
fragmentTransaction.replace(R.id.frame_container, fragment);
fragmentTransaction.commit();
return false;
}
我觉得这可以做到,因为toast能够检索listDataChild
内的字符串。我一夜之间无法解决的问题是如何检索listDataChild
字符串并将其传递,从片段1到片段2,其中片段2包含一个EditText框。如何将textview中的字符串放到edittext?
答案 0 :(得分:1)
您可以使用bundle ...
在片段之间传递数据Bundle args = new Bundle();
HomeFragment fragment = new HomeFragment();
args.putInt("key", value);
fragment .setArguments(args);
答案 1 :(得分:0)
在CategoryFragment中使用Bundle
传递数据,如
HomeFragment fragment = new HomeFragment();
Bundle bundle = new Bundle();
bundle.putString("key", listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition));
fragment.setArguments(bundle);
在HomeFragment
中,在onActivityCreated(....)
Bundle bumdle = getArguments();
if (bundle != null)
String value = bundle.getString("key");