问题描述
在我的应用我获取的所有图像和名称从服务器数据库的Android手机。如果模拟器的屏幕是,只有五个图像和名称越来越显示出来。在也只有五个名字越来越打印。当我滚动屏幕,有多少名,我可以看到屏幕越来越仅打印那么多的名字上。取而代之的是,所有的名字必须得到印刷滚动前。
In my application I am fetching all the images and names from a MySQL server database to the Android mobile. If the emulator screen is HVGA, only five images and names are getting displayed. In logcat also only five names are getting printed. When I scroll the screen, how many names I can see on the screen only that much names are getting printed. Instead of that, all the names have to get printed before scrolling.
这我的Java code:
This my Java code:
public class VegdishesListview extends BaseAdapter {
String qrimage;
Bitmap bmp, resizedbitmap;
Bitmap[] bmps;
Activity activity = null;
private LayoutInflater inflater;
private ImageView[] mImages;
String[] itemimage;
TextView[] tv;
String itemname,price,desc;
String[] itemnames;
String[] prices;
String[] descs;
HashMap<String, String> map = new HashMap<String, String>();
public VegdishesListview(Context context, JSONArray imageArrayJson) {
//inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// imageLoader=new ImageLoader(activity);
inflater=LayoutInflater.from(context);
this.mImages = new ImageView[imageArrayJson.length()];
this.bmps = new Bitmap[imageArrayJson.length()];
this.itemnames = new String[imageArrayJson.length()];
this.prices=new String[imageArrayJson.length()];
this.descs=new String[imageArrayJson.length()];
try {
for (int i = 0; i < imageArrayJson.length(); i++) {
JSONObject image = imageArrayJson.getJSONObject(i);
qrimage = image.getString("itemimage");
itemname = image.getString("itemname");
price=image.getString("price");
desc=image.getString("itemdesc");
itemnames[i] = itemname;
prices[i]=price;
descs[i]=desc;
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(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(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
vi = inflater.inflate(R.layout.vegdisheslistview, null);
TextView text=(TextView)vi.findViewById(R.id.vegdishestext);
ImageView image=(ImageView)vi.findViewById(R.id.vegdishesimage);
TextView text1=(TextView)vi.findViewById(R.id.vegdishesprice);
TextView text2=(TextView)vi.findViewById(R.id.vegdishesdesc);
image.setImageBitmap(bmps[position]);
text.setText(itemnames[position]);
text1.setText(prices[position]);
text2.setText(descs[position]);
System.out.println(itemnames[position]);
return vi;
}
当我滚动意味着许多itemNames中如何查看,很多项目我可以在这里进行打印。如何打印所有itemNames中除了滚动?
When I am scrolling means how many itemnames can view that many item I can print here. How do I print all itemnames instead of scrolling?
推荐答案
当你在实际存储的名称为您的适配器类的成员字段,可以打印它们在构造函数中,只是遍历数组。
As you are actually storing the names as a member field of your adapter class, you could print them inside the constructor, just iterating over the array.
这篇关于如何在Android的scorlling之前得到的侧基地适配器getview方法所有项名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!