0
是我的適配器類我想在我的適配器中使用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,但它不工作,有人能告訴我爲什麼嗎? 這裏是我的片段,我想獲得的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