Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count Total Number of List Items in a ListView

How to count Total Number of List Items in a ListView ?

I am writing a Church Application in which i am populating list using images stored into SD Card, but now i want to count total number of list items.

     // to upload whole list
     for(int position = 0; position < lstView.getAdapter().getCount(); position++)
                 {
                     flags.put(position, true);   
                 }

                 ((BaseAdapter) lstView.getAdapter()).notifyDataSetChanged();        
            }
        });

        /*** Get Images from SDCard ***/
        listSDCardImages = fetchSDCardImages();

        // ListView and imageAdapter
        lstView = (ListView) findViewById(R.id.listSDCardImages);
        lstView.setAdapter(new ListSDCardImagesAdapter(this));

        Toast.makeText(getApplicationContext(), "Total number of Items are:" + String.valueOf(position), Toast.LENGTH_LONG).show();
        }

Everytime i am getting 0

like image 945
Sophie Avatar asked May 17 '14 06:05

Sophie


People also ask

How to get total count of checked items in a list?

It seems rather straight forward, assuming you have a list of items you would get the total items count by using .Count on the list. To get the total checked items, you simply loop through all the elements and add 1 to the count of checed elements.

What is the difference between the string and integer in listview?

Where the String represents the item and the Integer represent how many times the item occurred in the ListView. In a single iteration you can populate the Dictionary: if the item is already present you just increment the Integer value, on the other hand, if the item doesn't yet exist in the Dictionary, then you add it and set the Integer to 0 .

How do I get the total count of checed elements?

Please Sign up or sign in to vote. It seems rather straight forward, assuming you have a list of items you would get the total items count by using .Count on the list. To get the total checked items, you simply loop through all the elements and add 1 to the count of checed elements.

Does itemcheck count prices together when selected row?

It does not count prices together when selected the row. And one more thing. Which method to use that the chekced rows will count in a real time. An event handler "ItemCheck" it does not do that. It count the previous checked row when another is checked - so one step behind. I got a float number into variable "myPrice".


1 Answers

Total list view count is

 lstView.getAdapter().getCount() ,

So use

Toast.makeText(getApplicationContext(), "Total number of Items are:" + lstView.getAdapter().getCount() , Toast.LENGTH_LONG).show();
like image 75
EminenT Avatar answered Oct 03 '22 15:10

EminenT