是否需要类的主要方法?
问题描述:
我读,因为它有必要在每个类这样的方法主要地方:是否需要类的主要方法?
public static void main(String args [ ]) { }
然而,没有我在我的当前项目类都包含这样的方法,到目前为止,我的应用程序的经验没有问题......这是我的课程之一供参考。
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};
}
是因为我扩展了某些东西(本例中是BaseAdapter)?现在,当前完成并实际运行的类有一个扩展,所以我想知道如果我的WIP类不需要main()方法。
没有,那肯定是没有必要有一个在所有类;只有在运行应用程序的入口点的类中才有必要。你在哪里读过这些? –
你从哪里读到的? –
不是。 Android中根本不需要public static void main(String args [])''。 – PPartisan