我正在按照以下示例在 android 中编写我的第一个 viewpager 程序:http ://www.edumobile.org/android/android-beginner-tutorials/view-pager-example-in-android-development/
该示例使用两个片段:包含文本视图的详细信息片段和包含图像视图的图像片段。这是图像片段的代码:
public class ImageFragment extends Fragment {
private final int imageResourceId ;
public ImageFragment (int imageResourceId)
{
this.imageResourceId = imageResourceId;
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.e("Test","Hello");
}
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState)
{
View view = inflater.inflate(R.layout.image_layout, container,false);
ImageView imageView = (ImageView)view.findViewById(R.id.imageView1);
**ImageView.setImageResource(imageResourceId);**
return view;
}
}
我无法从类型 imageview 中对非静态函数 setImageResource(int) 进行静态引用(问题语句以粗体显示)。如何解决这个问题?