获取位置片段到另一个片段

时间:2019-06-25 15:58:10

标签: java android android-fragments fragment

我想显示从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);


    }

}

1 个答案:

答案 0 :(得分:0)

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

var reply = sc.Context.Activity.CreateReply();
var card = new HeroCard
{
    Text = "Do you want to continue",
    Buttons = new List<CardAction>
    {
        new CardAction() { Title = "Yes", Type = ActionTypes.PostBack, Value = "Yes"},
        new CardAction() { Title = "No", Type = ActionTypes.PostBack, Value = "No"},
    },
};
reply.Attachments = new List<Microsoft.Bot.Schema.Attachment> { 
    card.ToAttachment() 
};
var options = new PromptOptions()
{
    Prompt = reply,
};
return await sc.PromptAsync(DialogIds.MyPrompt, options);

在代码下面的详细信息片段中

                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();

从mTloglist中可以获取数据!