我想更新GridView的内容,它使用自定义适配器显示一些图像。这是代码:
public class SudokuAdapter extends BaseAdapter
{
List<Integer> numbers;
private Context context;
public SudokuAdapter(Context context,List<Integer> numbers)
{
this.numbers=numbers;
this.context=context;
}
@Override
public int getCount() {
return numbers.size();
}
@Override
public Integer getItem(int position) {
return numbers.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public void updateList(List <Integer> numbers)
{
this.numbers=numbers;
this.notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// String drawableName = "R.drawable.sudo_1";
ImageView imageView = new ImageView(context);
//int resId=context.getResources().getIdentifier(drawableName , "drawable", context.getPackageName());
imageView.setImageResource(R.drawable.sudo_1);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(100, 100));
return imageView;
}
}
我正在调用updateList(),但应用程序将返回上一个活动。我怀疑我的getView()中存在问题。任何人都可以找出错误的原因吗?