Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在asyncTask中使用游标获取大量数据?_Java_Android_Android Listview_Android Asynctask_Android Cursor - Fatal编程技术网

Java 如何在asyncTask中使用游标获取大量数据?

Java 如何在asyncTask中使用游标获取大量数据?,java,android,android-listview,android-asynctask,android-cursor,Java,Android,Android Listview,Android Asynctask,Android Cursor,如何在asyncTask中使用游标以在listView中显示,因为我的获取数据是hugemetadata,我应该从asyncTask中使用。我需要一个链接,用于教程在asyncTask中使用游标 我有下面的代码 My Struct_Search.class: 在我的MainActivity.class中: 使用AsyncTaskLoader类 基本上,您必须使用LoaderManager框架来完成任务 这是一本关于上面所说的全部内容的很棒的教程 这是我以前使用过的一种模式: //Async c

如何在asyncTask中使用游标以在listView中显示,因为我的获取数据是hugemetadata,我应该从asyncTask中使用。我需要一个链接,用于教程在asyncTask中使用游标

我有下面的代码

My Struct_Search.class:

在我的MainActivity.class中:


使用AsyncTaskLoader类

基本上,您必须使用LoaderManager框架来完成任务

这是一本关于上面所说的全部内容的很棒的教程


这是我以前使用过的一种模式:

 //Async caller for threading
        class AsyncCaller extends AsyncTask<Void, Void, Void>
        {

            public AsyncCaller()
            {
               //initialize anything you may need here
            }

            ProgressDialog pdLoading = new ProgressDialog(/*Application Context here*/);
            @Override
            protected void onPreExecute() {
                super.onPreExecute();

                //this method will be running on UI thread, so change any UI here
                pdLoading.setMessage("Set loading message here");

                pdLoading.show();
            }
            @Override
            protected Void doInBackground(Void... params) {

                //this method will be running on background thread so don't update UI frome here
                //do your long running tasks here


                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                //put anything you need after execution here. 

                pdLoading.dismiss();
            }

        }

解释一下你所说的“巨大”是什么意思?只需在任务内部执行查询。只需在asyncTask中为我提供链接use cursor。asyncTask不适合@A.A想要的那种需求。。它适合于短期操作
    try {
        cursor = sql.rawQuery(
                "SELECT MetaDataID,Data,CategoryID,ParentID FROM BOOK WHERE DATA LIKE '"
                        + "%" + editable + "%'", null);
        array = new ArrayList<String>();
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    Struct_Search note = new Struct_Search();
                    note.MetaData = cursor.getInt(cursor.getColumnIndex("MetaDataID"));
                    note.Value = cursor.getString(cursor.getColumnIndex("DATA"));
                    note.Number = cursor.getInt(cursor.getColumnIndex("CategoryID"));
                    ParentID = cursor.getInt(cursor.getColumnIndex("ParentID"));
                    CursorSecond = sql.rawQuery("SELECT name FROM ContentList WHERE id ="+ ParentID, null);
                    if (CursorSecond != null) {
                        do {
                            CursorSecond.moveToFirst();
                            note.NameSureh = CursorSecond.getString(CursorSecond.getColumnIndex("name"));
                            CursorSecond.close();
                        } while (CursorSecond.moveToNext());
                    }
                    notes.add(note);
                } while (cursor.moveToNext());
            }
            adapter.notifyDataSetChanged();
        }
    } catch (Exception e) {
    } finally {
        cursor.close();
    }
 //Async caller for threading
        class AsyncCaller extends AsyncTask<Void, Void, Void>
        {

            public AsyncCaller()
            {
               //initialize anything you may need here
            }

            ProgressDialog pdLoading = new ProgressDialog(/*Application Context here*/);
            @Override
            protected void onPreExecute() {
                super.onPreExecute();

                //this method will be running on UI thread, so change any UI here
                pdLoading.setMessage("Set loading message here");

                pdLoading.show();
            }
            @Override
            protected Void doInBackground(Void... params) {

                //this method will be running on background thread so don't update UI frome here
                //do your long running tasks here


                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                //put anything you need after execution here. 

                pdLoading.dismiss();
            }

        }
new AsyncCaller().execute();