本文介绍了设置多个光标装载机与多个适配器 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序片段2光标装载机。他们中的每一个都有不同的数据集,并在不同的列表时使用。

I want to have two cursor loaders in my application fragment. Each one of them has different set of data and is used in different lists.

我发现的地方,用游标可以使用的getId()方法,然后用开关做一些事情。但是,总有方法: getLoaderManager()initLoader(0,NULL,这一点); 之后,它可以是这样的:

I found somewhere that with cursor you can use getId() method and then using switch do something. But, there is always method: getLoaderManager().initLoader(0,null,this); after which can be something like this:

适配器=新SimpleCursorAdapter(背景下,android.R.layout.simple_list_item_1,空,发件人,收件人,0);

此方法仅适用于一个光标,但如果我有适配器1 适配器2 ?我怎么能确定哪个光标是哪个适配器?

This method is only for one cursor, but what if I have adapter1 and adapter2? How can I determine which cursor is for which adapter?

推荐答案

我的解决方案是实现回调监听

My solution is to implement callback listeners

public class Query extends  FragmentActivity {//do not implement callbacks
getSupportLoaderManager().initLoader(Constants.LOADER_DAILY_TASK,
null,dailyTaskResultLoaderListener);//note listener not "this"
getSupportLoaderManager().initLoader(Constants.LOADER_OTHER_TASK,
null,otherTaskResultLoaderListener);//note listener not "this"

private LoaderCallbacks<Cursor> dailyTaskResultLoaderListener
= new LoaderCallbacks<Cursor>() {   
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle bun) {     
        return  new CursorLoader(getBaseContext(),
Constants.DAILY_TASK_URI,projection, selection,selArgs,null); }
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) 
{...}
public void onLoaderReset(Loader<Cursor> cursor) {...}};
private LoaderCallbacks<Cursor> otherTaskResultLoaderListener
= new LoaderCallbacks<Cursor>() {       

....我想你的想法

....I think you get the idea

这篇关于设置多个光标装载机与多个适配器 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 23:20