0

I have a listview in my app with custom rows layout. And the problem is some words randomly appearing/disappearing on scrolling. This words contains letters from spanish, e.g. á or ü and more.

For example: on activity created I can see in listview my row with title "I live in Nájera" (Nájera is a small town in Spain). An when I scroll listview, sometimes I can see only "I live in " and in another time everything is ok like it should be: "I live in Nájera".

I have table in sqlite on my app with this strings and load them from sqlite. What can I do to fix it?

EDIT

Adapter:

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

}

ListItem:

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

EDIT 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;
    }
tonyAndr
  • 177
  • 1
  • 3
  • 10
  • 2
    Its very hard to help without seeing code. The adapter and whatever model you're using for the database abstraction would be a great start! –  Feb 17 '15 at 19:16
  • I can hardly say that **ü** is a typical `Spanish` character (while **ç** looks like). It looks more `German`, to me. Without seeing any code, this is all I can tell. – Phantômaxx Feb 17 '15 at 19:19
  • Does the ListView row (and the Fragment which contains the ListView) include the xml header? – Phantômaxx Feb 17 '15 at 19:40
  • Yes, It has header. There are fragment's xml, header's xml and listview row's xml. – tonyAndr Feb 17 '15 at 20:17
  • Do the headers specify the UTF-8 encoding? – Phantômaxx Feb 17 '15 at 20:26
  • yep, I have this `` – tonyAndr Feb 17 '15 at 20:40
  • What's DatabaseHelper, how do you create and insert table ? What device do you use ? – eurosecom Feb 17 '15 at 22:55
  • I'm using `static class DBController extends SQLiteOpenHelper` and see edit with create/add – tonyAndr Feb 17 '15 at 23:23
  • Also, I'm getting all data from sqltable in JSONArray to operate with. But I don't see how all this can affect to listview, because I can see this words, that means they are successfully loaded from db and inserted into listview. They disappearing only on scrolling and appearing again so I think this all about recycler. – tonyAndr Feb 17 '15 at 23:33
  • And forgot about devices, I use samsung trend (4.1), lenovo k900 (4.2,4.3) and emulators (genymotion 4.1-5.0) – tonyAndr Feb 18 '15 at 00:06

1 Answers1

0

My bad... It wasn't about Spanish. Textview cut text because of width = "fill_parent". Now it changed to wrap_content and looks and works fine.

tonyAndr
  • 177
  • 1
  • 3
  • 10