你好,我有一个ViewPager
在Fragment
显示一些图像。我想开始一个新的Activity
为每个View
时,图像被点击。我的意思是,我显示一些图片在ViewPager
与circleadapter,我想打开一个新的寻呼机为每个图像与缩放选项。
这里是我的adapter.java
public class Adapter extends PagerAdapter {
private Activity _activity;
Context context;
LayoutInflater layoutinflater;
public Adapter(Context context) {
context = context;
layoutinflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
int[] mResources = {
R.drawable.img1,
R.drawable.img2,
};
@Override
public int getCount() {
return mResources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = layoutinflater.inflate(R.page_1, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.resim);
imageView.setImageResource(mResources[position]);
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
}
添加onclick选项后
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Class c=null;
switch (position){
case 0:
c=Yenii.class;
break;
case 1:
c=Yeni2.class;
break;
//and……
}
Context context = null;
Intent intent = new Intent(context,c);
context.startActivity(intent);
}
});
但现在我得到这个错误
java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“java.lang.String android.content.Context.getPackageName()”
2条答案
按热度按时间zwghvu4y1#
对代码进行以下更改:
最后,在FullScreenImageActivity OnCreate方法中:
fwzugrvs2#
已完成!