java - EditText Data to be displayed in a recycleview
问题描述
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 :
解决方案
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;
}
推荐阅读
- java - 我需要帮助来运行我的 Java 代码以让用户输入以下详细信息
- r - R中write.table的格式问题,utf-8原始编码
- python - 为什么我得到一个 TypeError: 'int' object not callable in a micro:bit MicroPython 程序?
- angular - Angular 中导入模块语句的顺序
- c - 在 cygwin 中编译 ESP8266_RTOS_SDK 并出错
- android-studio - 多次调用 WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION
- python - 每次移动所有元素时找到列表元素的所有可能组合
- java - 如何在 JavaFX Scene Builder 中制作固定大小的网格窗格?
- php - Laravel Shopify Oiset:如何正确使用 Oiset 功能?
- ckeditor - 如何在CKEditor 5中将光标放在末尾?