이미지 갤러리를 단편으로 만들려고하는데, 작동하지 않습니다. 내가 에뮬레이터에서 흰색 화면을 보여주는 앱을 실행하지만 내 logcat에는 오류가 없습니다. 내가 참조 tutorial .this이 자습서를 사용하고 나의 코드 내가 뭘 잘못조각 모음의 이미지 갤러리가 작동하지 않습니다. (안드로이드)
public View onCreateView(LayoutInflater inflater, ViewGroup container, AttributeSet attrs, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.imagegallery, container, false);
Gallery gallery = (Gallery) rootView.findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(getActivity()));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView <? > parent, View v, int position, long id) {
Toast.makeText(rootView.getContext(), "pic" + (position + 1) + " selected",
Toast.LENGTH_SHORT).show();
// display the images selected
ImageView imageView = (ImageView) rootView.findViewById(R.id.image1);
imageView.setImageResource(imageIDs[position]);
}
});
return rootView;
}
public class ImageAdapter extends BaseAdapter {
private Context context;
private int itemBackground;
public ImageAdapter(Activity activity) {
// sets a grey background; wraps around the images
TypedArray a = getActivity().obtainStyledAttributes(R.styleable.MyGallery);
itemBackground = a.getResourceId(R.styleable.MyGallery_android_galleryItemBackground, 0);
a.recycle();
}
// returns the number of images
public int getCount() {
return imageIDs.length;
}
// returns the ID of an item
public Object getItem(int position) {
return position;
}
// returns the ID of an item
public long getItemId(int position) {
return position;
}
// returns an ImageView view
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}
입니까?
응답 해 주셔서 감사합니다.하지만 작동하지 않습니다. –
@VibinRejiY 무엇이 문제입니까? –
나는 그것의 작은 실수를 생각한다 그것의 빈 screen.i를 보여주는 것을 모른다. –