[英]Create RecyclerView List From Edit Text Content
我自己解決了這個問題我做了什么來將數據從第二個片段轉回到第一個片段首先我創建interface
以將片段發送到fragment_1(具有recyclelerview)(其中有形式)
這是我的表單代碼
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.ppl_details_form,container,false);
PPL_Title_Spinner= (Spinner) view.findViewById(R.id.PPL_Spinner);
Title= (EditText) view.findViewById(R.id.ppl_title);
Address= (AutoCompleteTextView) view.findViewById(R.id.ppl_address);
Year= (EditText) view.findViewById(R.id.ppl_passing_year);
Description= (EditText) view.findViewById(R.id.ppl_description);
btn1= (Button) view.findViewById(R.id.ppl_map_button);
Save= (Button) view.findViewById(R.id.ppl_save);
Save_PPL.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
title=Title.getText().toString();
address= Address.getText().toString();
year=Year.getText().toString();
description=Description.getText().toString();
//PPL Wrapper
PPL_list_wrapper list=new PPL_list_wrapper(title,year,address);
Add_PPL=(PPL_transfer_data_to_list)getActivity();
Add_PPL.addLocation(list);
fragment_1 fragment1=new fragment_1();
FragmentTransaction fragmentTransaction=getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.Navigation_Main_Layout,fragment1);
fragmentTransaction.commit();
}
});
@Override
public void onAttach(Context context) {
super.onAttach(context);
try{
Add_PPL= (PPL_transfer_data_to_list) context;
}
catch (ClassCastException e){
throw new ClassCastException(getActivity().toString()+" Must Implement Interface");
}
}
然后我將infterface實現到Parent Activity中,然后從這樣的活動中調用fragment_1方法
@Override
public void addEvent(PPL_list_wrapper PPL_DATA) {
fragment_1 recycler=new fragment_1();
recycler.PPL_eve(PPL_DATA);
}
然后我將數據導入fragment_1並且必須在片段static
原因中制作arraylist而沒有靜態列表也將丟失其引用和數據並且它將停止將數據顯示到recyclerview
public void PPL_eve(final PPL_list_wrapper ppl_list_wrapper){
PPL_wrapper=ppl_list_wrapper;
event_details.add(ppl_list_wrapper);//Static ArrayList
adapter=new ppl_Recycler_Adapter(getActivity(),event_details);
adapter.notifyDataSetChanged();
}
我必須確保我的列表是靜態的
static List<PPL_list_wrapper> event_details=new ArrayList<PPL_list_wrapper>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.