标签: android-cursoradapter

BaseAdapter与CursorAdapter

我想知道何时使用每个适配器.根据我的经验,这篇文章 BaseAdapters在我从API获取数据时非常有用,并且我将它存储在Collection对象中.但是,CursorAdapter用于查询来自数据库,电话议程的内容......通常,内容也有内容提供者从中查询信息.

所以基本上BaseAdapter用于没有内容提供者访问它们的查询,因为在这种情况下,CursorAdapter将是最佳选择.是对的吗?

android baseadapter android-cursoradapter

5
推荐指数
1
解决办法
3626
查看次数

使用CursorAdapter维护listview中的复选框状态

对于我的Android项目,我有一个列表视图,其中包含每个项目的复选框.使用CursorAdapter类从SQLite数据库加载数据.但是,每当我滚动时,复选框位置将被移动并被移动到列表视图的下一部分.我该如何解决这个问题? 我的CheckBox问题的GIF 这是我的游标适配器类:

public class VocabCursorAdapter extends CursorAdapter {

private static final int DIFFICULT = 0;
private static final int FAMILIAR = 1;
private static final int EASY = 2;
private static final int PERFECT = 3;

public VocabCursorAdapter(Context context, Cursor c, int flags) {
    super(context, c, 0);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return LayoutInflater.from(context).inflate(R.layout.item_vocab, parent, false);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // Find fields to populate in …
Run Code Online (Sandbox Code Playgroud)

checkbox android listview android-cursoradapter android-checkbox

5
推荐指数
1
解决办法
1508
查看次数

如何使用cursoradapter实现自动完成功能

我有一个SQLite数据库,包含2个表4000+行,每行用于自动完成.我看到了非常简单的示例,它们使用字符串数组来提供自动完成功能,或者使用联系人列表来执行相同操作.显然,在我的案例中,这些都不起作用.对于自动完成,如何将自己的SQLite数据库与我自己的自动完成数据一起使用.我是否必须创建内容提供商?怎么样?请给我一些例子,因为我找不到任何例子.我已设法覆盖SQLiteOpenHelper将数据库从assets文件夹复制到android上的/ data/data/MY_PACKAGE/databases /文件夹.我创建了一个CursorAdapter使用我的自定义SQLiteOpenHelper并从中返回游标的自定义runQueryOnBackgroundThread.关于某些_id列丢失,我得到了奇怪的错误.我已将_id列添加到表中.我也不明白Filterable接口在做什么以及何时过滤我的数据.我需要覆盖哪些方法/类?谢谢.

java sqlite android autocomplete android-cursoradapter

4
推荐指数
1
解决办法
4718
查看次数

Android CheckBox - 删除以前的setOnCheckedChangeListener

我有一个应用程序,使用我自定义的CursorAdapter显示ListView.在我的自定义CursorAdapter.bindView中,我有一个CheckBox对象,我设置了检查值(基于光标上的列)并设置了clickListener.这是我的代码:

    CheckBox mCheckBox = (CheckBox) view.findViewById(R.id.list_done);
    mCheckBox.setChecked(isDone);
    mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
    {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
                AW.getDB().updateTask(c.getInt(c.getColumnIndex(ToDoDBAdapter.KEY_ID)), isChecked);
                TD.displayTasks();
        }
    });
Run Code Online (Sandbox Code Playgroud)

唯一的问题是,当Android回收我的视图时,onCheckedChangeListener仍处于活动状态,因此对setChecked()的调用会导致侦听器中的代码运行.我想知道如何在我包含运行的代码之前无效地使用onCheckedChangedListener.

checkbox android android-cursoradapter

4
推荐指数
2
解决办法
3483
查看次数

如何使用CursorAdapter和LoaderCallbacks在片段中实现ContentObserver?

我在a CursorAdapter中使用a ListFragment来加载和显示注释列表.

public class CommentsFragment extends ListFragment implements LoaderCallbacks<Cursor> {

    protected Activity mActivity;
    protected CursorAdapter mAdapter;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mActivity = getActivity();
        mAdapter = new CommentsCursorAdapter(mActivity, null, 0);
        setListAdapter(mAdapter);
        mActivity.getContentResolver().registerContentObserver(CustomContract.Comments.CONTENT_URI, false, new CommentsObserver());
        getLoaderManager().initLoader(0, null, this);
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle extras) {
        Uri uri = CustomContract.Comments.CONTENT_URI;
        return new CursorLoader(mActivity, uri, null, null, null, null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        mAdapter.swapCursor(cursor);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider contentobserver android-cursorloader android-cursoradapter

4
推荐指数
1
解决办法
8382
查看次数

简单的游标适配器需要最小的api 11问题

我正在开发一个应用程序,我需要从数据库中填充列表视图.我在以下代码中遇到兼容性问题

   dataAdapter = new SimpleCursorAdapter(
    this, R.layout.eventlisting, 
    cursor, 
    columns, 
    to,
    0);
Run Code Online (Sandbox Code Playgroud)

它需要最小api级别11,我的是8.是否有任何替代方法可以使此代码在api 8上运行.我可以使用支持库吗?

android android-listview android-sqlite android-cursoradapter

4
推荐指数
1
解决办法
2548
查看次数

使用CursorLoader和SimpleCursorAdapter的AutoCompleteTextView

我尝试使用db表的数据填充建议列表.但是我得到了StaleDataException.它会随机抛出,但总是在我将一个角色输入textview时.

这是我的代码:

CursorLoader扩展了CristianSimpleCursorLoader

public class TagCursorLoader extends SimpleCursorLoader {

    private String mSelection;
    private TagDbLoader mDbLoader;

    public TagCursorLoader(Context context, TagDbLoader dBLoader, String selection) {
        super(context);
        this.mDbLoader = dBLoader;
        this.mSelection = selection;
    }

    @Override
    public Cursor loadInBackground() {
        return mDbLoader.fetchContainingString(mSelection);
    }

}
Run Code Online (Sandbox Code Playgroud)

Loader回调:

public class TagCursorLoaderCallback implements LoaderCallbacks<Cursor>, CursorToStringConverter {

    private Context mContext;
    private TagDbLoader mdDbLoader;
    private SimpleCursorAdapter mAdapter;
    private String mSelection;

    public TagCursorLoaderCallback(Context context, TagDbLoader dBLoader, SimpleCursorAdapter adapter) {
        this.mContext = context;
        this.mdDbLoader = dBLoader; …
Run Code Online (Sandbox Code Playgroud)

android simplecursoradapter android-cursor android-sqlite android-cursoradapter

4
推荐指数
1
解决办法
3186
查看次数

为什么 CursorAdapter 与 BaseAdapter 不同?

我想问为什么CursorAdapter将创建视图并用数据填充它的过程拆分为newView()并且bindView()BaseAdapter执行此操作getView()

android baseadapter android-cursoradapter

4
推荐指数
1
解决办法
1874
查看次数

CursorAdapter如何在GridView中运行android

我在gridview上使用游标适配器时遇到问题,我使用光标从媒体商店加载照片.我意识到我的newView和bindView被完全调用了.我的意思是假设我有500张照片,newView也会被调用相同的次数.

我做错了什么吗?我以为它只会在屏幕上看到细胞时调用..

    public int taskA = 0;

public GalleryCursorAdapter(Context context, Cursor c) {
    super(context, c);
    // TODO Auto-generated constructor stub
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    int index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
    long id = cursor.getLong(index);

    Bundle idBundle = new Bundle();
    idBundle.putLong("id", id);

    Message msg = new Message();
    msg.setData(idBundle);

    ImageHandler imgHandler = new ImageHandler(context, (ImageView) view);
    imgHandler.sendMessage(msg);

    view.setTag(imgHandler);
    Log.w("task s",  " count");
}

@SuppressLint({ "NewApi", "NewApi" })
@Override
public View newView(Context context, …
Run Code Online (Sandbox Code Playgroud)

android gridview mediastore android-cursoradapter

4
推荐指数
1
解决办法
5764
查看次数

在ExpandableListView上分组数据

我在SQLite表中有以下格式的数据:

id|datetime|col1|col2
1|2013-10-30 23:59:59|aaa|aab
2|2013-10-30 23:59:59|abb|aba
3|2013-10-30 23:59:59|abb|aba
4|2013-10-31 23:59:59|abb|aba
5|2013-10-31 23:59:59|abb|aba
Run Code Online (Sandbox Code Playgroud)

我想实现一个,ExpandableListView以便数据分组datetime并显示如下:

> 2013-10-30 23:59:59 // Group 1
1|aaa|aab
2|abb|aba
3|abb|aba
> 2013-10-31 23:59:59 // Group 2
4|abb|aba
5|abb|aba
Run Code Online (Sandbox Code Playgroud)

我有一个习惯CursorAdapter,我可以很容易地填充ListView,显示每个项目的日期,但我不知道如何"分组"数据并填充它ExpandableListView- 你能不能给我任何提示?

android custom-cursor expandablelistview android-cursoradapter

4
推荐指数
1
解决办法
1700
查看次数