ниже мой адаптер классаЯ пытаюсь использовать метод getView в моем адаптере для gridview и его не работает?
public class ImageAdapter extends BaseAdapter {
private Context context;
public static ProfileData[]profileData={
new ProfileData(R.drawable.profileone,"profile1"),
new ProfileData(R.drawable.profiletwo,"profile2"),
new ProfileData(R.drawable.profilethree,"profile3"),
new ProfileData(R.drawable.profilefour,"profile4"),
new ProfileData(R.drawable.profilefive,"profile5"),
};
public ImageAdapter(Context context){
this.context=context;
}
@Override
public int getCount() {
return profileData.length;
}
@Override
public Object getItem(int position) {
return profileData[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
ImageView imageView=new ImageView(context);
imageView.setImageResource(profileData[position].getDrawable());
return imageView;
}
}
Как вы можете сказать, что я создал адаптер установить ImageView imageresource в профиль. Тем не менее, я реализую метод itemonclick в фрагменте, и я пытаюсь получить изображение в определенной позиции, но не работает, может кто-нибудь, пожалуйста, скажите мне, почему? Вот мой фрагмент, где я пытаюсь получить ImageView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_welcome_fourth,container,false);
adapter=new ImageAdapter(getContext());
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
ImageView image=(ImageView) adapter.getView(position,view,null);
image.setColorFilter(Color.BLUE);
}
});
return view;
}
Отличный ответный человек! Очень информативно – Eli