Application crashes while scrolling through ListView over and over

I have used list view and there are over 65,000 entries, scrolling is not fast and imprecise and also if I scroll over and over again the application crashes without any errors or any ANR dialog, can anyone help me solve this problem?

I am using SimpleCursorLoader

and CursorAdapter

and below is my code:

   private static class DotCursorLoader extends SimpleCursorLoader {

    private DbHelper mHelper;
    private CharSequence filter;

    public DotCursorLoader(Context context, DbHelper helper,
            CharSequence filter) {
        super(context);
        mHelper = helper;
        this.filter = filter;
    }

    @Override
    public Cursor loadInBackground() {

        return mHelper.getCursor(filter);
    }

}

private class DotCursorAdapter extends CursorAdapter {

    private Context mContext;
    private Typeface font;

    public class ViewHolder {
        TextView txtEng, txtGuj;
    }

    // public DotCursorAdapter(Context context, Cursor c, int flags) {
    // super(context, c, flags);
    // mContext = context;
    // }

    public DotCursorAdapter(Context context, Cursor c,
            boolean autoRequery) {
        super(context, c, autoRequery);
        mContext = context;

    }

    @Override
    public void bindView(View view, Context context,
            android.database.Cursor cursor) {
        ViewHolder holder = (ViewHolder) view.getTag();
        if (LibConstants.isEnglishEnabled(mActivity)) {

            holder.txtEng.setTextColor(settings.getInt(
                    LibConstants.English_Pref_Color_Key,
                    Color.BLACK));
            // txtEng.setTypeface(Typeface.DEFAULT);
            holder.txtEng.setTextSize(Integer.parseInt(settings
                    .getString("TextSize", "20")));
            holder.txtEng.setText(LibConstants.getWord(cursor
                    .getString(1)));
            Utils.setEnglishFont(holder.txtEng, mActivity);

            holder.txtGuj.setTextColor(settings.getInt(
                    LibConstants.Mean_Pref_Color_Key,
                    getResources().getInteger(
                            R.color.blue)));

            holder.txtGuj.setTypeface(font);
            holder.txtGuj.setTextSize(Integer.parseInt(settings
                    .getString("TextSize", "20")));
            holder.txtGuj.setText(LibConstants.getWord(cursor
                    .getString(2)));

        } else {

            holder.txtEng.setTextColor(settings
                    .getInt(LibConstants.Mean_Pref_Color_Key,
                            getResources().getColor(
                                    R.color.blue)));
            holder.txtEng.setTypeface(font);
            holder.txtEng.setTextSize(Integer.parseInt(settings
                    .getString("TextSize", "20")));
            holder.txtEng.setText((cursor
                    .getString(2)));

            holder.txtGuj.setTextColor(settings.getInt(
                    LibConstants.English_Pref_Color_Key,
                    Color.BLACK));
            holder.txtGuj.setTypeface(Typeface.DEFAULT);
            holder.txtGuj.setTextSize(Integer.parseInt(settings
                    .getString("TextSize", "20")));
            holder.txtGuj.setText(cursor
                    .getString(1));
            Utils.setEnglishFont(holder.txtGuj, mActivity);
        }

    }

    @Override
    public View newView(Context context,
            android.database.Cursor cursor, ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.list_item, parent, false);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.txtEng = (TextView) view
                .findViewById(R.id.txtEng);
        viewHolder.txtGuj = (TextView) view
                .findViewById(R.id.txtGuj);
        view.setTag(viewHolder);
        return view;
    }

}

      

+3


source to share


3 answers


One of the best examples of Endless Adapter can be found here



https://github.com/commonsguy/cwac-endless

+1


source


try this scrolling. while you need to refactor the view
NOTE: I haven't tested it, it might work ...



View con=null; 
 class ViewHolder
     {

         TextView tv,tv1;
         public ViewHolder(View v) {
            // TODO Auto-generated constructor stub

                tv=(TextView)v.findViewById(R.id.phone_number); 
                tv1=(TextView)v.findViewById(R.id.contact_name);


        }
     }
     //
      @Override
    public View newView(Context context,
            android.database.Cursor cursor, ViewGroup parent) {
            ViewHolder viewHolder ;
            if(con==null)
            {
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.list_item, parent, false);
                con=view;
        viewHolder = new ViewHolder(con);

        view.setTag(viewHolder);
         Log.i("getview","new view created");
        }

        return view;
    }

      

+1


source


I would do this using the download button more, after say 25 entries, and every time the list will load 25 more entries. The example here is one of the best for this kind of implementation.

You can also use swipe to update api availabel on GitHub.

0


source







All Articles