About the problem of asynchronous ListView data loading

You write a reading machine all video ListView
Because reading needs some time, so I used the asynchronous loading.
The following is my code, and did not reach the asynchronous loading, after the start or wait a few seconds to show up

I want to realize edge display, side loading effect, should be changed?
package com.siyehuazhilian.myvideoviewplayer;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends Activity {
// Loading data model
private static final int UPDATA = 1;
// The statement object
private ListView videoListView = null;
// Data collection
private ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
// Adapter
private SimpleAdapter adapter;

protected void onCreate(Bundle savedInstanceState) {
videoListView = (ListView) findViewById(R.id.listview_videolist);

adapter = new SimpleAdapter(this, list, R.layout.list_item,
new String[] { "title" }, new int[] { R.id.textview_item });


videoListView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {



protected void onResume() {
new Thread() {
public void run() {

private Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == UPDATA) {

* Load data
private void loadData() {
Cursor cursor = getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null,

while (cursor.moveToNext()) {
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("title", cursor.getString(cursor
hashMap.put("paht", cursor.getString(cursor



Started by Albert at December 13, 2016 - 1:25 AM

Paging display, page displays only 15, should not delay.
Once you read from the database is slow.
You can read the first 15, then the background background secretly asynchronous read more data stored in the list, and then the paging

Posted by Godfery at December 25, 2016 - 1:29 AM

I also do this now, specifically shows several to boot the machine performance, some high, some low 20 can display, can display 10, after many machine test, 12 of the insurance, and then determine the user pull at the top or drag the bottom of the refresh listview in multi display, if purely asynchronous loading, or delay, when the machine can not be loaded oncreate, by the way of oncreate general executive for the 5~7ms, if the data is a definitely more than the loading time, , ,

Posted by Pauline at January 08, 2017 - 2:09 AM