2012-02-16 124 views
1

在我的Activity類中,我在setContentView()行之後有以下代碼。需要對GridView.getChildCount()的說明

gridView = (GridView)findViewById(R.id.splitted_grid); 
gridView.setAdapter(new SplittedImageAdapter(this, splittedBitmaps)); 
gridView.setNumColumns((int) Math.sqrt(splittedBitmaps.size())); 
System.out.println(gridView.getChildCount()+" childs"); 

該活動完美地工作,還顯示一個3 * 3網格與所需的位圖圖像。但最後一行顯示輸出

0 childs 

按照該文檔中,getChildCount()方法應該表現出孩子的的,這意味着數它應該顯示

9 childs 

請幫我,我欠缺的。

回答

5

使用gridView.getCount()方法

+0

返回 與此AdapterView關聯的適配器擁有的物品數量 – Ajay 2012-02-16 13:34:28

+0

它可以工作,但getChildCount()方法的功能是什麼? – 2012-02-16 13:34:42

+0

ok,getChildCount()只返回視圖上的可見項 – Ajay 2012-02-16 13:39:08

0
gridview.getCount(); 

回報GridView的圖像/位圖的總數量。