计算ListView中列表项的总数

Sop*_*hie 15 android listview

如何计算ListView中列表项的总数?

我正在编写一个教会应用程序,其中我使用存储在SD卡中的图像填充列表,但现在我想计算列表项的总数.

     // 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();
        }
Run Code Online (Sandbox Code Playgroud)

每次我都0

Emi*_*enT 37

列表视图总数是

 lstView.getAdapter().getCount() ,
Run Code Online (Sandbox Code Playgroud)

所以使用

Toast.makeText(getApplicationContext(), "Total number of Items are:" + lstView.getAdapter().getCount() , Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)