I’m trying to develop Android apps via Java,Eclipse.
I’m trying to use this example.
My activity:
package grid.View;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getVieww(int position, View convertView, ViewGroup parent) {
ImageView imageVieww;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageVieww = new ImageView(mContext);
imageVieww.setLayoutParams(new GridView.LayoutParams(85, 85));
imageVieww.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageVieww.setPadding(8, 8, 8, 8);
} else {
imageVieww = (ImageView) convertView;
}
imageVieww.setImageResource(mThumbIds[position]);
return imageVieww;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
}
I have this error for all those “samples”:
sample_2 cannot be resolved or is not a field
What I’m supposed to do? :S
Thanks!
R.drawable.sample_2refers to a image called “sample_2” in your drawable folder.If it shows this error, either the image isn’t available in your drawable folder(s) (missing, different name?), or you haven’t imported the
R.javafile.By the looks of it, you haven’t downloaded the images described in the example and put them in your
drawablesfolder.