Reputation: 386
I'm reading in places that it's necessary to have a main method in each class like this:
public static void main(String args [ ]) { }
However, none of my classes in my current project contain such a method, and so far my app experiences no issues...here's one of my classes for reference.
public class GridAdapter extends BaseAdapter {
private final String[] classes = {"Database"}; // Sets the labels for each button
private Context mContext;
public GridAdapter(Context c) {
mContext = c;
}
public int getCount() { //autogenerated tab, returns length of an array.
return mThumbIds.length;
}
// The position an item is in in an array.
public Object getItem(int position) {
return mThumbIds[position];
}
// Gets the ID of each item in the array.
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) { // if it's not recycled, initialize some attributes
gridView = new View(mContext);
gridView = inflater.inflate(R.layout.gridset, null);
TextView textView = (TextView) gridView
.findViewById(R.id.label);
textView.setText(classes[position]);
ImageView imageView = (ImageView) gridView
.findViewById(R.id.img);
imageView.setImageResource(mThumbIds[position]);
} else {
gridView = convertView;
}
return gridView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.img};
}
Is it because I'm extending something (in this case BaseAdapter)? Right now the classes that are currently complete and actually function have an extension, So I am wondering if my WIP classes that don't will need a main() method.
Upvotes: 0
Views: 42
Reputation: 48252
Your reference reads "in at least one class" and pertains to a standalone Java SE program.
In Android you, however, do not need main
at all. Your Activities will be brought to life by Android OS calling callbacks into your Activities such as onCreate
, onPause
etc...
Upvotes: 4