-3

I have a fragment which contains a EditText part and a send button I need to send the same text entered in EditText by pressing the send button to the RecycleView. The text which I sent should be displayed above the edit text.

The design is like this :

enter image description here

4

1 回答 1

0
RecyclerView recyclerView;
List<Object> list;
RecycleAdapter recycleAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView =  inflater.inflate(R.layout.fragment_main, container, false);
    recyclerView = rootView.findViewById(R.id.recyclerview);
    list = new ArrayList<>();
    Button send= rootView.findViewById(R.id.button);
    final EditText editText = rootView.findViewById(R.id.editText);
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            list.add(0,editText.getText().toString());
            recycleAdapter.notifyDataSetChanged();

        }
    });
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayout.VERTICAL,true));
    recycleAdapter = new RecycleAdapter(getActivity(), list);
    recyclerView.setAdapter(recycleAdapter);

    return  rootView;
}
于 2018-07-30T14:29:41.740 回答