Listview using Endless adapter
<p>I have DB table with 10,000 rows which I want to display in the listview. I want to display first 20 and when the user scrolls down to the last item the next 20 should be loaded (and so on.). it really takes a lot of time to load all the datas in the listview so thats why i want it to load 20 datas first..</p>

<p>inside onCreate() Method the code is:</p>

<pre><code>    dbHelper = new WordDbAdapter(this);
    dbHelper.open();

    //Generate ListView from SQLite Database
    displayListView();
</code></pre>

<p>then on the displayListView() method the code is like this:</p>

<pre><code>  @SuppressWarnings("deprecation")
private void displayListView() {


  final Cursor cursor = dbHelper.fetchAllWords();

  // The desired columns to be bound
  String[] columns = new String[] {
          WordDbAdapter.KEY_WORD,
          WordDbAdapter.KEY_ROWID,

  };

  // the XML defined views which the data will be bound to
  int[] to = new int[] {

    R.id.Word,
    R.id.imgStar,

  };

  // create the adapter using the cursor pointing to the desired data
  //as well as the layout information
  dataAdapter = new SimpleCursorAdapter(
    this, R.layout.word_info,
    cursor,
    columns,
    to
    );

  ListView listView = (ListView) findViewById(R.id.Diclist);
  // Assign adapter to ListView
  listView.setAdapter(dataAdapter);
listView.setOnScrollListener(new OnScrollListener(){
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        int lastInScreen = firstVisibleItem + visibleItemCount;
        if(cursor != null){

            if(lastInScreen == totalItemCount &amp;&amp; isLoadingMore == false){
                isLoadingMore = true;

                loadedPage ++;
                new LoadWords().execute();
            }
        }
    }
    public void onScrollStateChanged(AbsListView view, int scrollState) {}
});




  listView.setOnItemClickListener(new OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView&lt;?&gt; listView, View view,
     int position, long id) {
   // Get the cursor, positioned to the corresponding row in the result set
   Cursor cursor = (Cursor) listView.getItemAtPosition(position);


   // Get the word name from this row in the database.
       String wordSelected =
               cursor.getString(cursor.getColumnIndexOrThrow("word"));
       String wordSyllabication =
               cursor.getString(cursor.getColumnIndexOrThrow("syllabication"));
       String wordPartofSpeech =
               cursor.getString(cursor.getColumnIndexOrThrow("partofspeech"));
       String wordMeaning =
               cursor.getString(cursor.getColumnIndexOrThrow("meaning"));
       String wordSpeak =
               cursor.getString(cursor.getColumnIndexOrThrow("speakword"));

       EditText TextDic = (EditText) findViewById(R.id.TextDic);
       TextDic.setText(wordSelected);
       speakMeaning = wordMeaning;
       speakSyllabication = wordSyllabication;
       speakPartOfSpeech = wordPartofSpeech;
       speakWord = wordSpeak;
       speakGetWord = wordSelected;


       //Toast.makeText(getApplicationContext(),
             //  wordSyllabication + "\n" + wordPartofSpeech + "\n" + wordMeaning , Toast.LENGTH_SHORT).show();

       }
      });



  EditText TextDic = (EditText) findViewById(R.id.TextDic);
  TextDic.addTextChangedListener(new TextWatcher() {

   public void afterTextChanged(Editable s) {
     speakWord = "";
     speakMeaning = "";

   }

   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
   dataAdapter.getFilter().filter(s.toString());
   }
  });

   dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
         public Cursor runQuery(CharSequence constraint) {
         return dbHelper.fetchWordsByWord(constraint.toString());
         }
     });


     }
</code></pre>

<p>then my AsyncTask is like this:</p>

<pre><code>private class LoadWords extends AsyncTask&lt;String, Void, Void&gt; {
    private final ProgressDialog dialog = new ProgressDialog(DictionaryActivity.this);

    Cursor cursor = dbHelper.fetchAllWords();

    @Override
    protected void onPreExecute() {
       this.dialog.setMessage("Loading books...");
       this.dialog.show();
    }

    public void execute() {
        // TODO Auto-generated method stub

    }

    @Override
    protected Void doInBackground(String... arg0) {
        try{
            cursor = dbHelper.fetchAllWords();
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
    @SuppressWarnings("deprecation")
    @Override
    protected void onPostExecute(final Void unused){
        if(cursor != null){
            if(dataAdapter == null){
                startManagingCursor(cursor);
                String[] columns = new String[] {
                          WordDbAdapter.KEY_WORD,
                          WordDbAdapter.KEY_ROWID,

                  };
                int[] to = new int[] {

                        R.id.Word,
                        R.id.imgStar,

                      };  
                getListView().setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
                dataAdapter = new SimpleCursorAdapter(DictionaryActivity.this, R.layout.word_info, cursor, columns, to);
                ListView listView = (ListView) findViewById(R.id.Diclist);
                  // Assign adapter to ListView
                listView.setAdapter(dataAdapter);


            }else{
                dataAdapter.notifyDataSetChanged();
            }
        }
        if(dialog != null &amp;&amp; dialog.isShowing()){
            dialog.dismiss();
        }
        isLoadingMore = false;
    }

    private AbsListView getListView() {
        // TODO Auto-generated method stub
        return null;
    }
}
</code></pre>
