R
R
Riodevista2015-02-04 22:38:25
Android
Riodevista, 2015-02-04 22:38:25

Why is the ListView slowly filling/drawing?

Hello!
The application has a list fragment that is populated from a database using a SimpleCursorAdapter.

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cursor = db.query(TABLE_NAME, null, null, null, null, null, null); // В коде непрямой вызов бд, но итог таков.
        ...
        scAdapter = new SimpleCursorAdapter(getActivity(), 
                            R.layout.rowlayout, cursor, from, to);
        ...
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_alarmclock, container, false);

        mListView = (AbsListView) view.findViewById(android.R.id.list);
        mListView.setAdapter(scAdapter);
        mListView.setOnItemClickListener(this);
        return view;
    }

In another activity I am adding an item to the database
ContentValues cv = new ContentValues();
     cv.put("text", entTime.getText().toString());
      ...
 db.insert(TABLE_NAME, null, cv); // Тоже не вызывается напрямую.

The problem is this:
If you add a new item to the database in the corresponding activity, then when you return to the activity that contains the fragment with the list, the drawing of some list fields will be clearly visible (they appear smoothly like that).
Experimentally, I established the following facts:
  • If we add an element with empty fields, then there is no smooth appearance effect, empty lines are already waiting for us when we return to the fragment. If you add at least one field with text that will be displayed in the TextView in rowlayout.xml, then the problem will resume.
  • This appearance effect is visible not from a certain number of already existing lines in the list, but from the area that deals with these lines. That is, if our new line falls into the bottom half of the screen, then it will have such a slow-motion effect with it. For example, in the list there are already 6 lines of 100dp in height, then we will add the seventh line, its appearance when returning to the fragment will be slowed down; add the eighth line, then the seventh and eighth lines will reappear slowly. If we do not add anything, then all eight lines will instantly appear. Now let's say we have 200dp lines, then everything will start repeating from about the fourth line.

The conclusion suggests itself that it is not the filling of the list with elements that is slow, but its rendering, but does a list with one text field per line require a lot of resources for this?
Something obscure is going on, and I can't figure out what exactly :(
Thanks in advance for any thoughts out loud about it.
UPD:
If you make a button in the same activity where the list fragment is located, when clicked, an element will be added to DB, and the adapter cursor is updated, then everything works like
clockwork.UPD2:
If you return from the new activity with the back button, then everything is OK.The problem is only when returning through the "back" button in the Action bar (getSupportActionBar().setHomeButtonEnabled(true);) .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Riodevista, 2015-02-05
@Riodevista

Suddenly, my experience will be useful to the next generation of developers.
The problem was that when returning using the "up" button in the Action bar, there was an animation embedded in the android itself: the current window "floats" on the user and disappears, and the list smoothly appears from top to bottom. For me, it all looked jerky and inferior from the fact that all animation was turned off on the device. Because it seemed that the problem was with the list. And I attributed the window twitching when returning to another bug, which I planned to solve later.
Here is such a story. The question remains how to get rid of this animation if it is disabled on the user's device.
The identified problem is solved here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question