-1

my code shows user apps in a listview. I want to show the total number of list items (apps) in my textview. how do i get the number?

    ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.activity_listview, results){


//  ArrayAdapter adapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, results ) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) { 
             TextView textView = (TextView) super.getView(position, convertView, parent);
             //Change this to your drawable
             Drawable myDrawable = getResources().getDrawable(android.R.drawable.ic_dialog_alert);
             textView.setCompoundDrawablesWithIntrinsicBounds( myDrawable , null, null, null);
             return textView;
        }
};  
    ListView listView = (ListView) findViewById(R.id.mobile_list);
    listView.setAdapter(adapter);
dr dre
  • 3
  • 2

2 Answers2

1

I understand that the variable "results" which you use to construct your adapter, is a "List" object, right? Then, if you use the code below:

int totalNumber = results.size();

Then, the variable totalNumber will be a int equal to the number of items on your list.

Alternatively, as Kevin.Lam said, you can also try to use

adapter.getCount();

to return the total number of items.

Cauê Jannini
  • 531
  • 1
  • 6
  • 10
0

Possibly by using ArrayAdapter's getCount() method - it shows "How many items are in the data set represented by this Adapter"

Kevin.Lam
  • 289
  • 1
  • 4
  • 16