显示滑动视图中的错误

时间:2013-11-20 06:00:57

标签: android android-listview

这是我的网格视图,通过单击Grid View的项目我尝试将项目的位置传递到全屏滑动视图中显示....下一个'FullscreenimageActivity类'将调用......... .....

public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = ((Activity) m1Context)
                .getLayoutInflater();
        View customRow1 = inflater.inflate(R.layout.gview, null);
        ImageView image = (ImageView) customRow1
                .findViewById(R.id.imageforgrid);
       switch (gotbread) {
        case 0:
            image.setImageResource(images2[position]);
            break;
        case 1:
            image.setImageResource(images1[position]);
            break;
        }
        image.setAdjustViewBounds(true);
        image.setScaleX((float) 0.5);
        image.setScaleY((float) 0.5);
        image.setOnClickListener(new OnImageClickListener(position));
        return customRow1;
    }
}
class OnImageClickListener implements OnClickListener {

    int _postion;

    // constructor
    public OnImageClickListener(int position) {
        this._postion = position;
    }

    @Override
    public void onClick(View v) {
        // on selecting grid view image
        // launch full screen activity
        Intent i = new Intent(Customgrid.this, FullScreenImageActivity.class);
        i.putExtra("position", _postion);
        startActivity(i);
    }

}

这是'FullscreenimageActivity类',用于在滑动视图中设置图像..

public class FullScreenImageActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fullscreen_view);
    ViewPager viewpager = (ViewPager) findViewById(R.id.pager);
    Intent i = getIntent();
    int position = i.getIntExtra("position", 0);

    Fullscreenimage adapter = new Fullscreenimage(
            FullScreenImageActivity.this);

    viewpager.setAdapter(adapter);

    // displaying selected image first
    viewpager.setCurrentItem(position);
}

}

这是全屏滑动视图图像的适配器类......

public class Fullscreenimage extends PagerAdapter {
public Integer[] images1 = { R.drawable.s_1, R.drawable.s_2, R.drawable.s_3 };

public Context mContext;


public Fullscreenimage(Context context) {
    super();
    this.mContext = context;

    // TODO Auto-generated constructor stub
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public boolean isViewFromObject(View arg0, Object arg1) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    // TODO Auto-generated method stub
    super.destroyItem(container, position, object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // TODO Auto-generated method stub
    LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
    View viewlayout = inflater.inflate(R.layout.layout_fullscreen_view,
            container, false);
    ImageView imageview = (ImageView) viewlayout
            .findViewById(R.id.imgDisplay);
    imageview.setImageResource(images1[position]);
    ((ViewPager) container).addView(viewlayout, 0);
    return viewlayout;
}

}

点击此图片,它应显示全屏图像..

enter image description here

显示完整图像的瞬间它只显示空白屏幕... PLZ帮帮我。

enter image description here

0 个答案:

没有答案