我的应用程序中有一个带有自定义行布局的列表视图。问题是滚动时随机出现/消失的一些单词。这个词包含来自西班牙语的字母,例如á或ü等等。
例如:在创建的活动中,我可以在列表视图中看到标题为“我住在纳赫拉”的行(纳赫拉是西班牙的一个小镇)。当我滚动列表视图时,有时我只能看到“我住在”,而在其他时候一切都很好,就像它应该的那样:“我住在 Nájera ”。
我在我的应用程序中有一个带有这个字符串的 sqlite 表,并从 sqlite 加载它们。我能做些什么来修复它?
编辑
适配器:
public class StageViewAlberguesAdapter extends ArrayAdapter<StageViewAlbItem> {
Context context;
private FragmentManager fragmentManager;
private static class ViewHolder {
TextView tvIcon;
TextView tvTitle;
TextView tvTel;
TextView tvBeds;
TextView tvSection;
ImageButton ibFindAlb;
}
public StageViewAlberguesAdapter(Context context, ArrayList<StageViewAlbItem> rows) {
super(context, R.layout.stage_albergues_list_item, rows);
this.context = context;
}
private FragmentManager getManager () {
try{
final Activity activity = (Activity) context;
return activity.getFragmentManager();
} catch (ClassCastException e) {
Log.d("___", "Can't get the fragment manager with this");
}
return null;
}
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
final StageViewAlbItem row = getItem(position);
ViewHolder viewHolder; // view lookup cache stored in tag
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.stage_albergues_list_item, parent, false);
viewHolder.tvIcon = (TextView) convertView.findViewById(R.id.iv_icon);
viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tv_alb_title);
viewHolder.tvTel = (TextView) convertView.findViewById(R.id.tv_alb_tel);
viewHolder.tvBeds = (TextView) convertView.findViewById(R.id.tv_alb_beds);
viewHolder.tvSection = (TextView) convertView.findViewById(R.id.tv_alblist_section);
viewHolder.ibFindAlb = (ImageButton) convertView.findViewById(R.id.ib_find_alb);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
// Populate the data into the template view using the data object
if (row.showSection) {
viewHolder.tvSection.setText(row.locality);
viewHolder.tvSection.setVisibility(View.VISIBLE);
} else {
viewHolder.tvSection.setVisibility(View.GONE);
}
viewHolder.tvIcon.setText("A");
viewHolder.tvTitle.setText(row.title);
viewHolder.tvTel.setText(row.tel);
viewHolder.tvBeds.setText(row.beds + " beds, " + row.type);
// Return the completed view to render on screen
return convertView;
}
}
项目清单:
public class StageViewAlbItem {
public String title, tel, type, beds, locality;
public boolean showSection = false;
double lat, lng;
int stage_id;
public StageViewAlbItem(String title,String tel,String type,String beds, String locality, boolean showSection, double lat, double lng, int stage_id) {
this.title = title;
this.tel = tel;
this.type = type;
this.beds = beds;
this.locality = locality;
this.showSection = showSection;
this.lat = lat;
this.lng = lng;
this.stage_id = stage_id;
}
}
编辑数据库控制器
public void onCreate(SQLiteDatabase database) {
String query;
query = "CREATE TABLE " + albergues.TABLE_NAME + " ( " + albergues.UID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
" " + albergues.TITLE + " TEXT, " + albergues.TYPE + " TEXT," + albergues.ADDRESS + " TEXT," +
" " + albergues.LOCALITY + " TEXT, " + albergues.BEDS + " VARCHAR(10)," +
" " + albergues.LAT + " DOUBLE," + " " + albergues.STAGE + " INTEGER," +
" " + albergues.LNG + " DOUBLE, " + albergues.TEL + " TEXT)";
database.execSQL(query);
}
public long insertAlbergue(String title, String locality, String tel, String beds, int stage, double lat, double lng, String type, String address) {
SQLiteDatabase db = dbController.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(dbController.albergues.TITLE, title);
cv.put(dbController.albergues.LOCALITY, locality);
cv.put(dbController.albergues.TEL, tel);
...
long id = db.insert(dbController.albergues.TABLE_NAME, null, cv);
return id;
}