我有一个片段,其中包含一个EditText部分和一个send按钮 我需要通过将发送按钮按下到RecycleView来发送在EditText中输入的相同文本。 我发送的文本应显示在编辑文本上方。
设计是这样的:
答案 0 :(得分: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;
}