0
在我的應用程序中,我已經實現了簡單的圖庫演示。 這裏我將根據用戶查看圖庫設置文本值。爲什麼我在我的應用程序中查看圖庫時無法獲得適當的文本值?
這裏是我的形象適配器類的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)));
}
}
現在Proble是,當我觀看庫圖像,文本值的變化。但我無法獲得我已經設置爲第二位和第二位的textValue。
我嘗試了許多,但每次我得到所有的價值,但不是第二個位置textValue和SecondLast位置textValue。
那麼,我的代碼有什麼錯?
這是最怪異的實施getView的我都碰上了:o – ingsaurabh
您getView()是最糟糕的實現,使用一些編碼格式如何使用convertView,以及如何膨脹的XML它在你的自定義適配器的getView()中。 – user370305
我只是想根據視圖庫更改文本值。我已經解決了這個問題。請看我的答案。 –