java - Large Database display on listview -



java - Large Database display on listview -

i have listview displays 500+ words , meaning. problem when load listview takes lot of time.. want add together listener such onscrolllistener when user load listview load 100 words when user scroll downwards add together more words.. used simplecursoradapter code this:

inside oncreate() method:

dbhelper = new worddbadapter(this); dbhelper.open(); //clean info dbhelper.deleteallwords(); //add info dbhelper.insertsomewords(); //generate listview sqlite database displaylistview();

outside oncreate() method:

@suppresswarnings("deprecation") private void displaylistview() { cursor cursor = dbhelper.fetchallwords(); // desired columns bound string[] columns = new string[] { worddbadapter.key_word, worddbadapter.key_rowid, }; // xml defined views info bound int[] = new int[] { r.id.word, r.id.imgstar, }; // create adapter using cursor pointing desired info //as layout info dataadapter = new simplecursoradapter( this, r.layout.word_info, cursor, columns, ); listview listview = (listview) findviewbyid(r.id.diclist); // assign adapter listview listview.setadapter(dataadapter); listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> listview, view view, int position, long id) { // cursor, positioned corresponding row in result set cursor cursor = (cursor) listview.getitematposition(position); // word name row in database. string wordselected = cursor.getstring(cursor.getcolumnindexorthrow("word")); 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; speakword = wordspeak; } }); 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) { homecoming dbhelper.fetchwordsbyword(constraint.tostring()); } }); }

i had 2 other class dbadapter , word. can help me.. thanks.

public class mylistmodel extends abstractlistmodel <string> { public string [] items = new string [1000]; @override public int getsize () { homecoming items.length; } @override public string getelementat (int index) { if (items [index] == null) loadrange (math.max (0, index - 50), math.min (1000, index + 50)); homecoming items [index]; } private void loadrange (int begin, int end) { // load items begin (inclusive) end (exclusive) database. (int = begin; < end; i++) { if (items [i] == null) items [i] = "item #" + + ", loaded @ " + new date (); } } public static void main (string [] args) { jlist <string> list = new jlist <string> (new mylistmodel ()); list.setprototypecellvalue (list.getmodel ().getelementat (999)); jframe frame = new jframe (); frame.setdefaultcloseoperation (jframe.exit_on_close); frame.getcontentpane ().setlayout (new borderlayout ()); frame.getcontentpane ().add ( new jscrollpane ( list, jscrollpane.vertical_scrollbar_always, jscrollpane.horizontal_scrollbar_as_needed), borderlayout.center); frame.pack (); frame.setvisible (true); } }

java android mysql sqlite

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -