首页 > 解决方案 > 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);
}

标签: android

解决方案


推荐阅读