Need
Though there is a difference between having the ability to attend and be willing to attend it is probably best not to try too hard to work out which of these a student has. Many teachers often assume that poor attention is a matter of deliberate choice. I would argue that this over simplifies a rather complex set of cognitive processes that we have only limited conscious control of. However, it is useful to consider attention being limited by capacity, concentration and motivation.
All of us have limited concentration before requiring a mental break. For the average graduate adult this is just over ten minutes. A break can be a few seconds if we are highly motivated to remain focussed but generally it is longer. For children the general rule of thumb is a minute of concentration for each chronological year so that the average five-year-old would have attention span of about five minutes.
Motivation has a complex influence on our attention span. We can all relate to struggling with focussing on topics that we lack interest with whilst being happily able to concentrate for long periods on our passions and things we enjoy. It is difficult to say how much conscious control we have over this. In school even the most conscientious and well-behaved student will struggle with complusory subjects they do not like. For students with learning or behaviour difficulties these additional concentration difficulties compound the situation leading to task breakdown. Equally, the difficulties with attention often lead to off-task behaviours that can then often escalate into behavioural challenges for the teacher.
Strategies
Try to be mindful of how long you are expecting students to concentrate for. Breaking down the lesson into a series of 'chunks' of between 5 and ten minutes can help students to switch their attention and provide the refocussing they need. These chunk transitions do not need to be big movement breaks or changes to their task, though these are the best forms of break, but can also include stopping the lesson to recap, summarise, give further instructions or even just give out praise!
It is not always possible to make every topic that we teach exciting and fun to illicit motivational interest and support their attention span. Remind students of the reasons why this learning is important. It can also be appropriate to indicate the negative consequences of not completing the task but this should be the last resort.