이미지를 표시합니다 (이 시점에서 하나의 지정된 국가에만 해당). 목록보기를 스크롤하면 이미지가 하나의 지정된 행에 나타나야합니다 열.이미지가있는 목록보기, 그러나 목록을 스크롤 할 때 이미지가 잘못된 행으로 표시됩니다.
예 : 'france'행에는 프랑스 국기가 표시되지만 다른 행에는 같은 플래그가 표시됩니다. 모든 행에있는 것은 아닙니다. 지금은 프랑스 국기 만 테스트하고 있습니다. 조회수 ListViews
에 convertView
을 통해 재활용 얻을 때문에
public class MyListAdapter extends SimpleCursorAdapter{
private Cursor cur;
private Context context;
private SQLiteDatabase db;
private static final String ASSETS_DIR = "images/";
private String Flag;
public MyListAdapter (Context context, Cursor c, SQLiteDatabase db) {
super(context, R.layout.countries_list_item, c, new String[] {}, new int[] {});
this.cur=super.getCursor();
this.context = context;
this.db=db;
}
private class ViewHolder {
TextView txtTitle, txtDate;
ImageView countryIcon;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.countries_list_item, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.lastName);
holder.txtDate = (TextView) convertView.findViewById(R.id.firstName);
holder.countryIcon = (ImageView) convertView.findViewById(R.id.country_icon);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
this.cur.moveToPosition(position);
holder.txtTitle.setText(this.cur.getString(this.cur.getColumnIndex("CountryID")));
holder.txtDate.setText(this.cur.getString(this.cur.getColumnIndex("Country")));
Flag =(this.cur.getString(this.cur.getColumnIndex("CountryImage")));
Flag=Flag.trim();
// Set country icon usign File path
try {
String imgFilePath = ASSETS_DIR +""+Flag;
Bitmap bitmap = BitmapFactory.decodeStream(this.context.getResources().getAssets().open(imgFilePath));
holder.countryIcon.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
return convertView;
}
}
http://stackoverflow.com/questions/7738527/getting-an-issue-while-checking-the-dynamically-generated-checkbox-through-list/7738854#7738854 –