Search code examples
androidtextview

Display the size of an arraylist to a textview


I want to display the size of ArrayList to a textview.

Textview textView;
ArrayList<Integer> mList = new ArrayList<>();
if(mList.size() < 7)
      {
         mList.add(1);
         mList.add(2);
         mList.add(3);
      }
textView.setText(mList.size());

It is giving me Exception:

android.content.res.Resources$NotFoundException: String resource ID #0x2

Solution

  • you may use..

    textView.setText(""+mList.size());
    

    or

    textView.setText(String.valueOf(mList.size()));
    

    or

    textView.setText(mList.size().toString());
    

    mark my answer accepted.