-4
我嘗試了很多代碼來顯示gridview中的圖像,但應用程序在模擬器中關閉了。這裏是我的代碼...在android應用程序中使用grideview顯示圖像
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final GridView ObjGrid = (GridView)findViewById(R.id.gridview);
ObjGrid.setAdapter(new ImageAdapter(this));
}
而且ImageAdapter類如上
public class ImageAdapter extends BaseAdapter {
int[] images = new int[]{
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6
};
private Context cont;
public ImageAdapter(Context applicationContext) {
cont = applicationContext;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return images.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int arg0, View ConvertView, ViewGroup arg2) {
ImageView iv;
if(ConvertView == null)
{
iv = new ImageView(cont);
iv.setLayoutParams(new GridView.LayoutParams(180, 180));
iv.setScaleType(ScaleType.CENTER_CROP);
iv.setPadding(0, 8, 8, 8);
}
else
{
iv=(ImageView)ConvertView;
}
iv.setImageResource(images[arg0]);
return null;
}
}
請給我的解決方案,如果有任何可能給項目文件downlode然後這對我來說是非常有幫助的... 謝謝
你應該考慮改進你的問題,因爲現在我什麼都不懂。 – 0gravity 2012-07-05 19:06:17
這與asp.net有什麼關係? – FoamyGuy 2012-07-05 19:09:51