比較應用程序的名字,我有以下示例代碼...如何獲得和Android的
public class ImageAdapter extends BaseAdapter {
public static String PACKAGE_NAME;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return helloThumbIds.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 getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(100, 100));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
PACKAGE_NAME = (String) mContext.getApplicationContext().getPackageName();
//How to compare this with Class Name
if(PACKAGE_NAME=="HelloWorld.class"){
imageView.setImageResource(helloThumbIds[position]);
}else if(PACKAGE_NAME=="HelloWhere.class"){
imageView.setImageResource(hellowhereThumbIds[position]);
}
return imageView;
}
Integer[] helloThumbIds = {
R.drawable.1,
R.drawable.2};
Integer[] hellowhereThumbIds = {
R.drawable.3,
R.drawable.4};
}