0

Hi i am trying to load some data from msql db using asynctaskloader .

int customerid=0;
public void loaddata(int custId) {
    customerid = custid;
    getLoaderManager().initLoader(0, null, this);
}


@Override public Loader<List<AppEntry>> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created.  This
    // sample only has one Loader with no arguments, so it is simple.
    return new AppListLoader(getActivity(),customerid);
}

@Override public void onLoadFinished(Loader<List<AppEntry>> loader, List<AppEntry> data) {
    // Set the new data in the adapter.
    log.d("price of item",""+data);
}

@Override public void onLoaderReset(Loader<List<AppEntry>> loader) {
    // Clear the data in the adapter.
}

i am calling the loaddata() method from an activity and passing different customer id each time ,but it only gives me old result what i passed first time. It is there something call notify adapter change as we have in other adapters.

4

2 回答 2

2

initLoader只启动一次加载器并再次调用它,根据文档什么也不做:

如果加载器尚不存在,则创建一个并(如果活动/片段当前已启动)启动加载器。否则,最后创建的加载器将被重新使用。

如果你想多次调用它,你想用restartLoader代替它。

于 2013-05-27T17:20:08.370 回答
1

你可以试试这个,但它总是会在随后的尝试中重新启动加载器:

 if(getSupportLoaderManager().getLoader(Consts.LOADER_2)==null)
        getSupportLoaderManager().initLoader(Consts.LOADER_2, null, this);
         else
             getSupportLoaderManager().restartLoader(Consts.LOADER_2, null, this);
于 2013-07-28T00:52:13.550 回答