簡體   English   中英

從編輯文本內容創建RecyclerView列表

[英]Create RecyclerView List From Edit Text Content

在此輸入圖像描述 我有片段中的RecyclerView ,我想當用戶按下“添加新行”下面的按鈕時它將重定向到新片段,直到這里沒有問題我可以實現它但現在我希望填寫表格詳細信息在recyclerview中顯示為新行

正如您在上面的圖片中看到的,用戶可以動態地在RecyclerView中添加行,並且還有從列表中刪除行的每行的右上角。

所以, 我想做的是

1)如果用戶按下保存事件,我將如何使用表單輸入向行添加行,然后向用戶顯示新添加的行,並在表單中輸入他輸入的詳細信息

總之,我想在表單中動態添加行,用戶輸入表單,當用戶按行項目右上角的十字按鈕時也從列表中刪除行

我自己解決了這個問題我做了什么來將數據從第二個片段轉回到第一個片段首先我創建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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM