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:
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.
I have tryed many but every time i got all value but not the second position textValue and SecondLast position 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.
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;
}