Я пытаюсь написать ViewHolder
для этого GridView
списка, но каждый раз получаю сообщение об ошибке. Можете ли вы сказать мне, как сделать правильный ViewHolder для этого списка gridView?
мой код:
public static String[] stringArray = {"IRAN","Uganda",
"Ukraine","United Arab Emirates","United Kingdom","United States Minor Outlying Islands",};
public int[] imageArray = {R.drawable.iran,R.drawable.united_states,R.drawable.iran,R.drawable.russia,
R.drawable.iran,R.drawable.united_states,R.drawable.iran,R.drawable.uk,
R.drawable.iran,R.drawable.united_states };
public CountryImageAdapter(Context mContext) {this.mContext = mContext;}
@Override
public int getCount() {return imageArray.length;}
@Override
public Object getItem(int position) {return imageArray[position];}
@Override
public long getItemId(int position) {return 0;}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {View v;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.sample_gridlayout, null);
v.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TextView textView = (TextView) v.findViewById(R.id.country_text);
ImageView imageView = (ImageView) v.findViewById(R.id.ivGallery);
textView.setText(stringArray[position]);
imageView.setImageResource(imageArray[position]);
return v;}