Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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
Android 如何使用Sqlite在可扩展列表视图中添加分页&;异步任务_Android_Sqlite_Android Asynctask_Expandablelistview - Fatal编程技术网

Android 如何使用Sqlite在可扩展列表视图中添加分页&;异步任务

Android 如何使用Sqlite在可扩展列表视图中添加分页&;异步任务,android,sqlite,android-asynctask,expandablelistview,Android,Sqlite,Android Asynctask,Expandablelistview,有一个Sqlite数据库,我在可扩展列表视图内部的分页实现方面遇到了问题 我想获取数据(一次十条记录)并在可解释列表视图中显示这些记录 如何通过AsyncTask实现这一目标,与服务器进行后台交互以显示数据库中的信息 主要活动 /** The count. */ static int count=0; listDataHeader = new ArrayList<String>(); childDataHashMap = new HashMap<String, List<

有一个Sqlite数据库,我在可扩展列表视图内部的分页实现方面遇到了问题

我想获取数据(一次十条记录)并在可解释列表视图中显示这些记录

如何通过AsyncTask实现这一目标,与服务器进行后台交互以显示数据库中的信息

主要活动

/** The count. */
static int count=0;

listDataHeader = new ArrayList<String>();
childDataHashMap = new HashMap<String, List<ChildInfo>>();
databaseHelper = new DatabaseHelper(this);
// readFromFile();
csvToSqlite();

// get the listview
expListView = (ExpandableListView) findViewById(R.id.expandableListView);
txtViewLoadMore=(TextView) findViewById(R.id.textViewLoadMore);
// LoadMore button
        Button btnLoadMore = new Button(this);
        btnLoadMore.setText("Load More");
        // Adding Load More button to lisview at bottom
        expListView.addFooterView(btnLoadMore)
txtViewLoadMore.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View view) {
        count = count+1;
        //call AsyncTask for loading data in Expandable list view in background
        new NearBuyAsyncTask(MainActivity.this).execute();  
    }
});     
getExpandableListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader,childDataHashMap);
// setting list adapter
expListView.setAdapter(listAdapter);
我得到以下错误

原因:java.lang.RuntimeException:无法在内部创建处理程序 尚未调用Looper.prepare()的线程


我会搜索延迟加载场景和代码示例,以便理解提前获取数据的逻辑,并在需要时缓存数据以供使用。这就是你需要寻找的。
public void getExpandableListData() {
    // Group data//
    // databaseHelper = new DatabaseHelper(getApplicationContext());{
    Cursor cursor;
    if(count==0)
    {
        cursor = databaseHelper.getGroupData();
    }
    else{
         cursor = databaseHelper.getLoadMoreData(count);
    }
    cursor.moveToFirst();
    Log.i(TAG, "cursor.getCount()" + cursor.getCount());
    do {
        String categoryDescription = cursor.getString(cursor.getColumnIndex("categorydesc"));
        int categoryId = cursor.getInt(cursor.getColumnIndex("CategoryId"));

        // Child data//
        Cursor cursorChild = databaseHelper.getChildData(categoryId);
        List<ChildInfo> childList = new ArrayList<ChildInfo>();
        cursorChild.moveToFirst();
        while (cursorChild.moveToNext()) {
            String businessName = cursorChild.getString(cursorChild .getColumnIndex("BusinessName"));
            phoneNumber = cursorChild.getString(cursorChild.getColumnIndex("ph_Phone"));
            String landMark = cursorChild.getString(cursorChild .getColumnIndex("LandMark"));
            ChildInfo childInfo = new ChildInfo(businessName, phoneNumber,  landMark);
            childList.add(childInfo);
        }
        childDataHashMap.put(categoryDescription, childList);
        } while (cursor.moveToNext());
    cursor.close();
}
@Override
protected Void doInBackground(Void... params) {
    // TODO Auto-generated method stub
    activity = new MainActivity();
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            MainActivity mainActivity = new MainActivity();
            mainActivity.getExpandableListData();
        }
    });

    return null;
}