2013-05-05 52 views
0

我有一個問題,我使用ImagePagerAdapter來顯示基於內部數據庫的動態圖庫位圖。我的代碼根據位置實際顯示正確的位圖。 但我也想顯示圖片的描述(使用textView),我的代碼顯示的描述,但不給我正確的描述img似乎使用instantiateItem的變量位置不返回我需要。Android ImagePagerAdapter,顯示文本視圖

我使用兩個數組,我有存儲描述和位圖。 mydesc [] =要存儲每個IMG的描述 mydraw [] =要存儲我的抽拉

我使用此功能的位置

public Object instantiateItem(ViewGroup container, int position) { 

有我對ImagePager

private class ImagePagerAdapter extends PagerAdapter { 
    @Override 
    // Count the element on my array 
    public int getCount() { 
      return mydraw.length; 
    } 

@Override 
public boolean isViewFromObject(View view, Object object) { 
     return view == ((ImageView) object); 
} 


    /** 
    * Target: Displaying the data according to the position 
    * 
    * 
    * @param container, position 
    * @return imageView, The view displaying in the page 
    */ 
@Override 
public Object instantiateItem(ViewGroup container, int position) { 
    Context context = MainActivitySocialisation.this; 
    ImageView imageView = new ImageView(context); 
    //TextView textView = new TextView(context); 
    int padding = context.getResources().getDimensionPixelSize(
     R.dimen.padding_medium); 

    // Display the current image 
    imageView.setPadding(padding, padding, padding, padding); 
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 
    imageView.setImageDrawable(mydraw[position]); //(mImages[position]); 

    // Display the name of the Image  
    textView.setText(mydesc[position]); 

    ((ViewPager) container).addView(imageView,0); 
    return imageView; 
} 
代碼

感謝您的幫助,

+0

你在哪裏初始化了textView? – bakriOnFire 2013-05-05 16:36:29

+0

textView是公開的,我可以訪問它,並改變值沒有問題。 public TextView textView; – 2013-05-05 17:17:36

回答

0

我找到了我的問題的解決方案,我已經設置了一個監聽器到我的viewpager和使用

viewPager.getCurrentItem();