[英]Why I am not able to getProper Text Value while Viewing Gallery in my application?
In My Application i have Implement the Simple Gallery Demo. 在我的应用程序中,我已实现了简单画廊演示。 Here i am going to set text Value according to user viewing the gallery. 在这里,我将根据查看图库的用户设置文本值。
Here is my Code for GetView method of Image Adapter class: 这是我的Image Adapter类的GetView方法的代码:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(this.myContext);
i.setImageResource(this.myImageIds[position]);
/* Image should be scaled as width/height are set. */
i.setScaleType(ImageView.ScaleType.FIT_XY);
/* Set the Width/Height of the ImageView. */
i.setLayoutParams(new Gallery.LayoutParams(300, 300));
switch(position){
case 0:
productName.setText("dimond540_1");
break;
case 1:
productName.setText("diamond540_2");
break;
case 2:
productName.setText("diamond_ink_bottle_1");
break;
case 3:
productName.setText("diamond_ink_bottle_2");
break;
case 4:
productName.setText("diamond_ink_bottle_3");
break;
case 5:
productName.setText("micarta_1");
break;
case 6:
productName.setText("micarta_2");
break;
case 7:
productName.setText("vac700_1");
break;
case 8:
productName.setText("vac700_2");
break;
}
return i;
}
/** Returns the size (0.0f to 1.0f) of the views
* depending on the 'offset' to the center. */
public float getScale(boolean focused, int offset) {
/* Formula: 1 / (2 ^ offset) */
return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
}
}
Now the Proble is, While i am viewing the gallery image, text value is change. 现在的问题是,当我查看图库图像时,文本值正在更改。 But i am not able to get the textValue that i have set as second position and Second last position. 但是我无法获取设置为第二位置和第二倒数第二位置的textValue。
I have tryed many but every time i got all value but not the second position textValue and SecondLast position textValue. 我已经尝试了很多,但是每次我都获得了所有值,但第二个位置textValue和SecondLast位置textValue都没有。
So, whats wrong in my code? 那么,我的代码有什么问题呢?
I have solve My Question as below: 我已经解决了我的问题,如下所示:
I have made the Method in that class and in that method i change the TextValue and it works great. 我已经在该类中创建了方法,并且在该方法中,我更改了TextValue,并且效果很好。
Code: 码:
public long getItemId(int position) {
switch(position){
case 0:
productName.setText("Dimond540(1)");
break;
case 1:
productName.setText("Dimond540(2)");
break;
case 2:
productName.setText("Diamond Ink Bottle(1)");
break;
case 3:
productName.setText("Diamond Ink Bottle(2)");
break;
case 4:
productName.setText("Diamond Ink Bottle(3)");
break;
case 5:
productName.setText("Micarta(1)");
break;
case 6:
productName.setText("Micarta(2)");
break;
case 7:
productName.setText("Vac700(1)");
break;
case 8:
productName.setText("Vac700(2)");
break;
}
return position;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.