2011-11-16 61 views
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。

那麼,我的代碼有什麼錯?

+0

這是最怪異的實施getView的我都碰上了:o – ingsaurabh

+0

您getView()是最糟糕的實現,使用一些編碼格式如何使用convertView,以及如何膨脹的XML它在你的自定義適配器的getView()中。 – user370305

+0

我只是想根據視圖庫更改文本值。我已經解決了這個問題。請看我的答案。 –

回答

0

我解決我的問題如下:

我已經在這個類和該方法做出的方法我改變TextValue和它的偉大工程。

代碼:

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; 
    } 
相關問題