android - When I put the application in the background and return to the application again, the edittext runs unexpectedly
问题描述
I have a frame layout in my Activity class. I replace the fragment here. I create a Layout inside the fragment.
There is also edittext in the layout. By making a for loop, I create a layout for all the elements in the list and set the required String value to the edittext.
Everything works normally when I first turn on sleep. When I put the application in the background and come back to the application, it sets the string values in the list to the edittext, but it sets the last element of the list in the entire edittext.
However, it is necessary to set different string values for each edittext. In debug mode, everything seems to be set correctly in the code, but it appears different on the screen.
What is the reason?
Code Part:
List<String> bags = new ArrayList<>();
bags.add("pencil");
bags.add("paper");
for(String bag : bags){
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dataLayout = inflater.inflate(R.layout.layout_data, null);
EditText myEditText = (EditText) dataLayout.findViewById(R.id.value_edit_text);
myEditText.setText(bag);
formLayout.addView(myEditText);
}
解决方案
推荐阅读
- html - 如何从html页面调用方法到类
- javascript - 如何将 ajax 响应以 json 格式填充到输入文本字段中
- react-native - 在drawernavigation中无法导航到draweritem
- git - 推送后如何更正Gitlb中的提交?
- android - 我需要关于在 firebase 中创建的聊天系统的报告
- reactjs - 通过 const 中的道具反应路由器“到”
- c++ - 如何在codelite中运行多个程序
- reactjs - React redux 应用程序使用以前的数据显示表单,直到重新加载页面
- powershell - 如何通过Powershell将分发列表添加为Office365上另一个分发列表的成员?
- apache-kafka - Kafka - 重置分区错误