这是我的基础适配器类 这个类名称包含我想要的所有食物名称
enter code here
public class MainMenulist extends BaseAdapter {
int i;
String qrimage;
Bitmap bmp, resizedbitmap;
Bitmap[] bmps;
Activity activity = null;
private LayoutInflater inflater;
private ImageView[] mImages;
String[] itemimage;
TextView[] tv;
String itemname;
public String[] itemnames;
HashMap<String, String> map = new HashMap<String, String>();
public MainMenulist(Context context, JSONArray imageArrayJson) {
inflater=LayoutInflater.from(context);
this.mImages = new ImageView[imageArrayJson.length()];
this.bmps = new Bitmap[imageArrayJson.length()];
this.itemnames = new String[imageArrayJson.length()];
try {
for ( i = 0; i < imageArrayJson.length(); i++) {
JSONObject image = imageArrayJson.getJSONObject(i);
qrimage = image.getString("menuimage");
itemname = image.getString("menuname");
itemnames[i] = itemname;
byte[] qrimageBytes = Base64.decode(qrimage.getBytes());
bmp = BitmapFactory.decodeByteArray(qrimageBytes, 0,
qrimageBytes.length);
int width = 100;
int height = 100;
resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height,
true);
bmps[i] = bmp;
mImages[i] = new ImageView(context);
mImages[i].setImageBitmap(resizedbitmap);
mImages[i].setScaleType(ImageView.ScaleType.FIT_START);
// tv[i].setText(itemname);
}
System.out.println(itemnames[i]);
System.out.println(map);
} catch (Exception e) {
// TODO: handle exception
}
}
public int getCount() {
return mImages.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
vi = inflater.inflate(R.layout.mainmenulistview, null);
TextView text=(TextView)vi.findViewById(R.id.menutext);
ImageView image=(ImageView)vi.findViewById(R.id.menuimage);
image.setImageBitmap(bmps[position]);
text.setText(itemnames[position]);
return vi;
}
}
这是另一个类ManagerHandset.java,我想在上面的类中打印itemnames []。我想在ManagerHandset.java.please中获取项目名称帮助我
答案 0 :(得分:0)
写一个类MyMain
,如 -
class MyMain extends Application(){....}
当应用程序启动时,将调用此类。现在,您在该类中维护itemnames[]
的静态实例,如 -
class MyMain extends Application(){
public static Object itemNames[];
}
现在,只要您拥有itemNames
的值,就可以使用MyMain.itemNames = this.itemNames;
实例化itemNames
。现在,您可以在整个应用程序中使用itemNames
。快乐的编码!