gpt4 book ai didi

java - 获取 fragment 到另一个 fragment 的位置

转载 作者:行者123 更新时间:2023-12-02 03:54:36 26 4
gpt4 key购买 nike

我想显示从dasboardFragment到dasboardDetailFragment的详细数据。根据其位置与listView.setOnItemClickListener

dashboardFragment.java

public class dashboardFragment extends Fragment {
ListView lv;

SearchView searchView;
ArrayAdapter<String> adapter;
String[] menuItem ={"Panti Asuhan Arif Rahman Hakim",
"Panti Asuhan Undaan Surabaya",
"Panti Asuhan Yatim Piatu Al Mu'Min",
"Panti Asuhan At Taqwa",
"Panti Asuhan Al-Fatih",
"Panti Asuhan Al Kahfi",
"Panti Asuhan BJ Habibie",
"Panti Asuhan KH. AR. FAKHRUDDIN",
"Panti Asuhan Karya Asih",
"Panti Asuhan Ibnu Sina Kertajaya",
"Panti Asuhan Yatim Cahaya Insani",
"Griya Yatim & Dhuafa surabaya",
"Panti Asuhan Wachid Hasyim",
"Panti Asuhan Al-Hikmah Muhammadiyah",
"Panti Asuhan Amanah",
"Yayasan Panti Asuhan Sabilillah",
"Rumah Anak Pondok Kasih",
"Panti Asuhan Lydia",
"Panti Asuhan Yatim Aisyiyah",
"Panti Asuhan Al Jabbar "};
private ArrayList<String> ada;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fragment_dashboard, container, false);
lv = (ListView) view.findViewById(R.id.list_item);
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,menuItem);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

FragmentTransaction fr= getFragmentManager().beginTransaction();
fr.replace(R.id.fragment_container, new dasboardDetailFragment());
fr.commit();
}
});

return view;

}
}

dasboardDetailFragment.java

public class dasboardDetailFragment extends Fragment {

public dasboardDetailFragment() {
// Required empty public constructor
}
private TextView Getnama, Getjam, GetAlamat;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dasboard_detail, container, false);


}

}

最佳答案

您可以在 setOnItemClickListener 上使用以下内容

                Gson mGson = new Gson();
Datum cars = mData.get(position); // grabbing the cars list from another object
String carsListString = mGson.toJson(cars);
dasboardDetailFragment myTripDetailFragment = new dasboardDetailFragment();
Bundle mBundle = new Bundle();
mBundle.putString(AppConstants.DATA, carsListString);
myTripDetailFragment.setArguments(mBundle);
FragmentTransaction fr= getFragmentManager().beginTransaction();
fr.replace(R.id.fragment_container, myTripDetailFragment);
fr.commit();

在代码下面的详细信息 fragment 中

        Gson mGson = new Gson();
String mImagesList = getArguments().getString(AppConstants.DATA);
String mTlogsList = mGson.fromJson(mImagesList, new TypeToken<String>(){}.getType());

从mTloglist你可以获取数据!

关于java - 获取 fragment 到另一个 fragment 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56757947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com