Listview和消失的西班牙语单词

时间:2015-02-17 19:11:42

标签: android android-listview encoding android-viewholder

我的应用中有自定义行布局的listview。而问题是在滚动时随机出现/消失的一些词。这个词包含来自西班牙语的字母,例如áü等等。

例如:在创建的活动中,我可以在listview中看到标题为“我住在Nájera”的行(Nájera是西班牙的一个小镇)。当我滚动列表视图时,有时我只能看到“我住在”,而在另一个时间,一切都很好,就像它应该是:“我住在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;
    }
}

编辑DBController

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;
    }

1 个答案:

答案 0 :(得分:0)

我的不好......这不是西班牙语。由于width =“fill_parent”,Textview剪切文本。现在它改为wrap_content,看起来很好。