I have 30 items in the ListView . If I write something in the zero element, then when scrolling down, these data may be generally below, or even in place 4 12 15 28.

So I decided that it would be better if I somehow disabled the re-creation of components in the ListView .

Or in EditText catch the moment when a person loses focus, so that I save the data to a file, and then read it.

 @Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getLayoutInflater().inflate(R.layout.main_list, null); } EditText editText = (EditText)convertView.findViewById(R.id.editText); editText.setHint("asdsadad"); // SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); // sharedPreferences.getString("pos" + position, ""); return convertView; } 
  • You are obviously misusing the reuse mechanism. Show where you change the value of the view, then something is shown in other elements. - Yuriy SPb
  • By the way, one more thing is strange. If you activate the EditText and scroll through the ListView, then somewhere on the 10th element the focus will be on the 10th element. What for? - Andro
  • one
    Use the ViewHolder pattern in your Adapter, or use the recently appeared RecycleView component - Werder instead of the ListView.
  • RecycleView is better? And there precisely this chip will earn? - Andro

1 answer 1

Since the items are repeatedly reused, you need to take care of restoring the state of a particular item to a certain position, for this you need to save the input from the EditText to a separate storage that will be linked to the positions in the list and then use this data when (re)) creating item It is necessary not only to restore the input, but also to forcibly clear the EditText if there is no input in it. See this answer for a more detailed solution.

To extract data from list items in EditText when focus is lost, see this answer (item 2).

What you will use ListView or RecyclerView does not matter much. As well, the ViewHolder pattern is not suitable for solving your problem (although its use is highly recommended), which stores only links to widgets (excludes repeated calls to the findViewById() method), and not the contents of these widgets.