private Context mContext;
private int[] colors = new int[] { Color.WHITE, 0x30aaaaaa };
private int[] dotColors = new int[7];
private List<Integer> sta;
private TasksDataSource datasource;
private int con=1000;
public Integer[] mThumbIds = {
R.drawable.green, R.drawable.green,
R.drawable.green, R.drawable.green,
R.drawable.green, R.drawable.green,
R.drawable.green, R.drawable.green,
R.drawable.green, R.drawable.green,
R.drawable.green, R.drawable.green,
R.drawable.green, R.drawable.green,
R.drawable.green
};
public ImageAdapter(Context context, List<Integer> content){
sta = content;
datasource = new TasksDataSource(context); //here
datasource.open();
mContext=context;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int[] st = new int[sta.size()];
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(20, 20));
return imageView;
}
我有一个动态初始化循环,它在前面的代码中有一些改变..
public Integer[] mThumbIds = new Integer[con];
for(int i = 0;i < st.length;i++)
{
st[i] = sta.get(i);
Log.i("st::" + st[i]," ");
}
int ii=0,jj=0;
while(ii<con)
{
if(st[jj]==0)
{
mThumbIds[ii]=R.drawable.red;
}
else if(st[jj]==1)
{
mThumbIds[ii]=R.drawable.green;
}
else
{
mThumbIds[ii]=R.drawable.grey;
}
}
上述添加不起作用并无限运行并停止。我想要的是,在 mThumbIds[ii] 为 0 时显示红色 img ,当 mThumbIds[ii] 为 1 时显示绿色,当 mThumbIds[ii] 为 2 时显示灰色。我该如何实现?