标签: android-cursoradapter

如何获取Android Contact缩略图

我有一个listview适配器,我正在尝试以下newView方法:

@Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {

        final LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(layout, parent, false);

        long contactId = Long.valueOf(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID))); 
        String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
        boolean hasPhone = Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))); 
        String thumbnailUri = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)); 

        TextView name_text = (TextView) v.findViewById(R.id.name_entry);
        if (name_text != null) {
            name_text.setText(contactName);
        }

        name_text.setTag(new Contact(contactId, hasPhone));

        ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail);
        if (thumbnailUri != null) {
            thumbnail.setImageURI(Uri.parse(thumbnailUri));
        } else {
            thumbnail.setImageResource(R.drawable.ic_launcher);
        }

        return v;
    }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试解析存储在thumbnailUri中的Uri时,我收到以下错误:

   08-09 01:58:38.619: I/System.out(1471): …
Run Code Online (Sandbox Code Playgroud)

android listview android-cursoradapter

11
推荐指数
1
解决办法
7916
查看次数

自定义游标适配器多次调用bindView

我已经忍受了几个月和几个月的问题(但现在我正在进行性能调整).但是,我现在迫切需要知道为什么我的适配器感觉有必要bindView在记录上运行多达4次.

我有一个自定义游标适配器填充gridview.

一些调试显示正在发生的事情:

03-08 14:46:47.980: I/AdapterCursorGrid(20724): newView()
03-08 14:46:48.470: I/AdapterCursorGrid(20724): bindView()
03-08 14:46:48.570: I/AdapterCursorGrid(20724): --------------------------
03-08 14:46:48.570: I/AdapterCursorGrid(20724): bindView() Record Id: 1
03-08 14:46:48.570: I/AdapterCursorGrid(20724): bindView() Cursor Position: 0
03-08 14:46:48.570: I/AdapterCursorGrid(20724): bindView() View Type: 0
03-08 14:46:48.570: I/AdapterCursorGrid(20724): --------------------------
03-08 14:46:48.600: D/AdapterCursorGrid(20724): bindView() Avatar empty...
03-08 14:46:48.690: D/AdapterCursorGrid(20724): bindView() Picture creation...
03-08 14:46:49.490: I/AdapterCursorGrid(20724): bindView()
03-08 14:46:49.501: I/AdapterCursorGrid(20724): --------------------------
03-08 14:46:49.501: I/AdapterCursorGrid(20724): bindView() Record Id: 1
03-08 14:46:49.501: I/AdapterCursorGrid(20724): bindView() Cursor Position: 0
03-08 14:46:49.501: I/AdapterCursorGrid(20724): bindView() …
Run Code Online (Sandbox Code Playgroud)

android android-gridview android-cursoradapter

10
推荐指数
2
解决办法
5175
查看次数

如何创建Cursor数据而不从Android应用程序中的DataBase获取数据?

在我的Android应用程序中,我使用Sqlite DataBase来存储来自服务器的数据.我使用ContentProvider和ContentResolver访问DataBase中的数据,并使用CursorAdapter将数据绑定到ListView.一旦将数据插入DataBase,将通知CursorAdapter更新ListView.此外,每当我滚动ListView时,我都会从DataBase表中获取新数据,并且ListView将被更新.但是一旦我到达表行的末尾,我需要直接从服务器获取数据而不存储到DataBase中并在ListView中更新它.现在,当我使用接受Cursor数据的CursorAdapter时,如何绑定一个不是来自DataBase的新数据集?是否可以在不从DataBase获取数据的情况下创建Cursor数据,并在ContentProvider中使用ChangeCursor()方法来更新ListView?如果没有,还有其他方法可以达到同样的效果吗?

android android-contentprovider android-cursor android-cursoradapter

10
推荐指数
1
解决办法
4237
查看次数

Listview中的CursorAdapter

我正在使用CursorAdapter在listview中读取数据库.我在列表的每个项目中都有一个复选框,当用户选中复选框时,我的数据库中的收藏列会更改是,并且项目会添加到收藏夹中.

一切都很好,最喜欢的列已更改,但当我在列表中向上和向下滚动时,复选框将取消选中.如果您重新启动应用程序,则复选框已被选中

我该怎么办这个问题:

对不起,我的英语不好:

CursorAdapter类:

public class MyAdapter extends CursorAdapter {

    Context b;   
    LayoutInflater inflater;
    @SuppressWarnings("deprecation")
    public MyAdapter(Context context, Cursor c) {
        super(context, c);
        inflater = LayoutInflater.from(context);
        b= (Context) context;
    }

    @SuppressWarnings("unused")
    @Override
    public void bindView(View view, Context context, final Cursor cursor) {
        // TODO Auto-generated method stub

        TextView tv1 = (TextView)view.findViewById(R.id.txt_name);
        TextView tv2 = (TextView)view.findViewById(R.id.txt_numer);

        tv1.setText(cursor.getString(2));
        tv2.setText(cursor.getString(3));

        final int pos = cursor.getPosition();

        final CheckBox repeatChkBx = (CheckBox)view.findViewById(R.id.favorite_check);

        String me = cursor.getString(cursor.getColumnIndex("like"));

        if (me.equals("yes")) {
            repeatChkBx.setChecked(true);
        } else {
            repeatChkBx.setChecked(false); …
Run Code Online (Sandbox Code Playgroud)

checkbox android listview android-cursoradapter

10
推荐指数
1
解决办法
1533
查看次数

CursorAdapter有什么用?

CursorAdapter有3个构造函数.让我们看一下指南和参考.

1)CursorAdapter(上下文上下文,光标c)

不推荐使用此构造函数.不鼓励使用此选项,因为它会导致在应用程序的UI线程上执行Cursor查询,从而导致响应能力较差甚至应用程序无响应错误.或者,使用带有CursorLoader的LoaderManager.

2)CursorAdapter(Context context,Cursor c,boolean autoRequery)

允许控制自动重新查询的构造函数.建议您不要使用它,而是使用 CursorAdapter(Context,Cursor,int).

3)CursorAdapter(上下文上下文,Cursor c,int标志)

推荐的构造函数.

flags 用于确定适配器行为的标志; 可以是FLAG_AUTO_REQUERY和FLAG_REGISTER_CONTENT_OBSERVER的任意组合.

FLAG_AUTO_REQUERY 不推荐使用此常量.不鼓励使用此选项,因为它会导致在应用程序的UI线程上执行Cursor查询,从而导致响应能力较差甚至应用程序无响应错误.或者,使用带有CursorLoader的LoaderManager.

FLAG_REGISTER_CONTENT_OBSERVER.将CursorAdapter与CursorLoader一起使用时,不需要此标志.

CursorAdapter(Context context,Cursor c,int flags)是推荐的构造函数,但是可能的标志是2,当使用带有CursorLoader的CursorAdapter时,不推荐使用其中一个,而不需要另一个.如果我使用带有CursorLoader的CursorAdapter,我必须使用此构造函数并将零作为标志传递?在这种情况下,构造函数是否与#1相同?

android constructor android-loadermanager android-cursoradapter

9
推荐指数
1
解决办法
4404
查看次数

从CursorAdapter.get()返回对象

我重写了CursorAdapter,我需要得到最后一项,问题是CursorAdapter实际上有一个get()方法......但是source是一个db,它返回一个普通的对象!(我甚至不知道它是什么,我希望它返回一个Cursor对象......)

无论如何,我如何让它返回我的Wrapper数据库行类的实例?

示例:说我的db有这样的行:

id |名字| 姓

我从那里做了一个班级的.

现在我想从游标适配器获得一个Person get(int i)方法...

android android-cursoradapter

9
推荐指数
2
解决办法
1万
查看次数

Android:列'_id'不存在

我收到了这个错误

IllegalArgumentException:列'_id'不存在

当使用a SimpleCursorAdapter从我的数据库中检索时,表确实有这个_id列.注意到这是一个常见问题,我尝试在线解决一些解决方案,但没有一个能够解决.这是我的游标查询:

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.quoterow, myCursor, new String[]{"_id", "quote"}, new int[]{R.id.quote});
Run Code Online (Sandbox Code Playgroud)

虽然我应该提到原来没有包含该_id列,但我最近添加了这个以尝试解决问题.有没有人有任何可能有助于解决问题的想法?

sqlite android android-sqlite android-cursoradapter

8
推荐指数
1
解决办法
1万
查看次数

分页列表和CursorLoader

我需要实现分页列表,使用Loader获得CursorContentProvider.我有页脚,当用户点击它 - 我需要添加下一个记录列表.

如何刷新列表中的数据Loader?或者我该怎么办?

android android-listview android-cursorloader android-cursoradapter

8
推荐指数
1
解决办法
868
查看次数

如何使用CursorAdapter从ListView中删除所选项目

我正在使用CursorAdapter,下面是我的适配器类.我的列表包含两个文本视图和每行一个按钮.现在,单击按钮我想从列表中删除所选项目以及从数据库中删除.如何从数据库中获取所选项的ID,以便我可以删除它然后通知适配器(刷新列表).

public class MyAdapter extends CursorAdapter {

    Cursor c;
    LayoutInflater inflater;
    Context context;
    private String TAG = getClass().getSimpleName();

    public MyAdapter(Context context, Cursor c) {
        super(context, c);
        this.c = c;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public void bindView(View view, Context context, final Cursor cursor) {

        TextView txtName = (TextView) view.findViewById(R.id.txt_name);
        txtName.setText(cursor.getString(cursor.getColumnIndex(Helper.tbl_col_username)));
        TextView txtPassword = (TextView) view.findViewById(R.id.txt_password);
        txtPassword.setText(cursor.getString(cursor.getColumnIndex(Helper.tbl_col_password)));

        Button button = (Button) view.findViewById(R.id.btn_delete);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                Log.d(TAG, "Button Click ");
            }
        }); …
Run Code Online (Sandbox Code Playgroud)

android onclicklistener android-cursoradapter

8
推荐指数
1
解决办法
1万
查看次数

Listview与CursorAdapter

我正在开发一个用CursorAdapter显示Phone联系人的应用程序.当我运行它时,我面对一个列表视图,它只重复了一个联系人("david"是我的一个联系人,只是在listview中重复)

大卫017224860

大卫017224860

大卫017224860

大卫017224860

大卫017224860

大卫017224860.

.

.

.

我的活动看起来像

public class Contacts extends Activity {    
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contacts);

    Cursor cursor = getContentResolver()
        .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
               null, null, null, null);

    startManagingCursor(cursor);

    ContactCursorAdapterCT adapter= new ContactCursorAdapterCT(Contacts.this, cursor);
     ListView contactLV = (ListView) findViewById(R.id.listviewblcontactsDB);

    contactLV.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

我的cursorAdapter看起来像:

public class ContactCursorAdapterCT extends CursorAdapter {
       public ContactCursorAdapterCT(Context context, Cursor c) {
    super(context, c);
    // TODO Auto-generated constructor stub
}

@Override
public void bindView(View view, Context context, Cursor cursor) {

    while (cursor.moveToNext()) { …
Run Code Online (Sandbox Code Playgroud)

android listview android-cursoradapter

8
推荐指数
1
解决办法
3万
查看次数