Error – Market cannot be resolved or is not a field.
News cannot be resolved or is not a field.
Weather cannot be resolved or is not a field.
I am trying an example on GridView. I added images named Market, News and Weather to res>>drawable-mdpi>> folder. But Eclipse fails to recognize it. The images are in *jpeg * format. What may be wrong? Can you please help? Here I am posting the code
public class MainActivity extends Activity
{
// Images to display-----------------------//
Integer[] imageIds = {
R.drawable.Market,
R.drawable.News,
R.drawable.Weather
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridView = (GridView) findViewById(R.id.gridview);// Bring gridView into context from main.xml
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent,
View v, int position, long id)
{
Toast.makeText(getBaseContext(), "pic " + (position + 1) + " selected", Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter
{
private Context context; // Context class object - context
public ImageAdapter(Context c)
{
context = c;
}
//return number of images
public int getCount()
{
return imageIds.length;
}
public Object getItem(int position) // return type of getItem method is an Object
{
return position;
}
public long getItemId(int position)
{
return position;
}
//returns an ImageView view--------------
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if(convertView == null)
{
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(5, 5, 5, 5);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setImageResource(imageIds[position]);
return imageView;
}
}
}
I tried creating a resource with name Weather (a picture placed in
drawable-mdpi) and I gotin Eclipse. I thought the resource names should be snake-styled by restriction, but I found this thread where the guy states that camel case is also all right. This means that the only restriction is not to have the first letter capital.