The landlord wrote a reading machine for all video ListView
Because reading takes time, so I used the way
loaded asynchronouslyHere is my code, and did not achieve the purpose of asynchronous loading, start or to wait a few seconds until all displayed
I want to achieve edge shows the effect of side loading, how should I change?
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 {
/ / Load data mode
private static final int UPDATA = 1;
/ / Declare a control object
private ListView videoListView = null;
/ / Data collection
private ArrayList> list = new ArrayList > ();
/ / Adapter
private SimpleAdapter adapter;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
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.setAdapter (adapter);
videoListView.setOnItemClickListener (new OnItemClickListener () {
@ Override
public void onItemClick (AdapterView parent, View view,
int position, long id) {
}
});
}
@ Override
protected void onResume () {
super.onResume ();
new Thread () {
public void run () {
loadData ();
};
.} Start ();
}
private Handler handler = new Handler () {
public void handleMessage (android.os.Message msg) {
if (msg.what == UPDATA) {
adapter.notifyDataSetChanged ();
}
};
};
/ **
* Load Data
*
* /
private void loadData () {
Cursor cursor = getContentResolver (). Query (
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null,
null);
while (cursor.moveToNext ()) {
HashMaphashMap = new HashMap ();
hashMap.put ("title", cursor.getString (cursor
. GetColumnIndex (MediaStore.Video.Media.TITLE)));
hashMap.put ("paht", cursor.getString (cursor
. GetColumnIndex (MediaStore.Video.Media.DATA)));
list.add (hashMap);
handler.sendEmptyMessage (UPDATA);
}
cursor.close ();
}
}
Reply:
Pagination, page displays only 15, should not delay it.
Your one-time read from the database is relatively slow.
You can first read the first 15, then sneak backstage backstage asynchronous read more data to be stored inside the list, and then paged
Reply:
I have done this, you want to turn a few specific sub-display, and some high-performance machine that can display 20, and some low can display 10, after many tests loom, 12 most insurance, and determine whether the user is pulled the top or bottom refresh listview pulled again when in multi-display, if purely asynchronous loading, or there is a delay, the machine can no longer oncreate when loading is complete, by the way oncreate generally perform as 5 ~ 7ms, if the data is more than one absolute Over load time,,,
No comments:
Post a Comment