0
我正在尝试为网格视图中的特定网格项设置填充。我对gridChild得到空值,而试图得到它的使用getChildAt如何访问使用位置的网格视图中的特定网格项
我在的onCreate编写这些代码()查看方法:
GridView MainGalleryview = (GridView) findViewById(R.id.main_gallery_gridview);
MainGalleryview.setAdapter(new CustomGalleryAdapter(this));
final CustomGalleryAdapter adapterData = new CustomGalleryAdapter(this);
for(int i = 0; i<adapterData.getCount(); i++) {
mediaPath = adapterData.images.get(i);
boolean ImageCheck = mediaPath.indexOf("WhatsApp/") > 0;
Log.d("Check: ", "-----" + mediaPath +"----");
if(ImageCheck){
ViewGroup gridChild = (ViewGroup) MainGalleryview.getChildAt(i);
if(gridChild != null)
gridChild.setPadding(-10, -10, -10, -10);
else
Log.d("Error: ", "*******" + gridChild + "********");
}
}
看来你在回答中忘记了一些东西,你要求OP在没有指定的情况下做一些事情 – Sidewinder94
@Tamas Kandala:我检查了我的日志,我确信nullpointer不是来自adapterData.images。我如何在我的适配器类中使用getChildAt? – Ramesh