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
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.
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 .
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.
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".
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With