伙计们。
我正在尝试在 android 中使用自定义微调器实现动态图像。一切顺利,除了我的情况没有显示图像,它仅作为我的布局中的默认图像出现。谁能指出我的错误是什么?下面是我的代码。
public class CustomSpinnerAdapter extends SimpleCursorAdapter {
int layoutn;
LayoutInflater mInflater;
private final Cursor mCursor;
private final int mLayout;
private final LayoutInflater mLayoutInflater;
private final Context mContext;
int arr_images[] = { R.drawable.us,
R.drawable.uk, R.drawable.eur,
R.drawable.cn, R.drawable.ml, R.drawable.mr};
public CustomSpinnerAdapter (Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, R.layout.spinnertext, c, from, to);
this.mContext = context;
this.mCursor = c;
this.mLayout = layout;
this.mLayoutInflater = LayoutInflater.from(context);
}
private final class ViewHolder {
public TextView Title;
public ImageView flag;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(mLayout, parent, false);
viewHolder = new ViewHolder();
viewHolder.Title = (TextView) convertView
.findViewById(R.id.currencytitle);
viewHolder.flag = (ImageView) convertView
.findViewById(R.id.imageView1);
}
else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.flag.setImageResource(arr_images[position]);
return convertView;
}
}
编辑:我的听众代码和光标:
mDb = mHelper.getWritableDatabase();
String[] headers2 = new String[] {MyDbHelper.COL_Currfirst ,MyDbHelper.COL_Titleone};
cursl = mDb.query(MyDbHelper.TABLE_NAME, headers2, MyDbHelper.COL_Currsecond + "=" + "?",
new String[] { "EUR" }, null, null, null );
adapters1 = new CustomSpinnerAdapter(this, R.layout.spinnertext, cursl,
headers2, new int[] { R.id.currencytitle , R.id.titlesub});
fromc.setAdapter(adapters1);
toc.setAdapter(adapters1);