|
public class test extends Activity {
/** Called when the activity is first created. */
TextView text;
public Integer[] img={R.drawable.icon,R.drawable.icon,R.drawable.icon,R.drawable.icon,R.drawable.icon,R.drawable.icon,R.drawable.icon,R.drawable.icon,R.drawable.icon};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g=(Gallery)findViewById(R.id.gallery1);
g.setAdapter(new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter{
Context mContext;
private LayoutInflater mInflater;
public ImageAdapter(Context c){
mContext=c;
mInflater = LayoutInflater.from(mContext);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return img.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
ViewHolder vh;
Log.i("ee", position+" "+arg1);
if(arg1==null)
{
arg1= mInflater.inflate(R.layout.newfile, null);
vh=new ViewHolder();
vh.Image=(ImageView) arg1.findViewById(R.id.imagelistIVimage);
vh.Image.setLayoutParams(new LinearLayout.LayoutParams(200, 200));
arg1.setTag(vh);
}
else
vh=(ViewHolder)arg1.getTag();
vh.Image.setImageResource(img[position]);
return arg1;
}
}
public class ViewHolder {
ImageView Image;
}
}
为什么我用logcat看arg1的内容
不管怎么拖动都是null? |
|