2017-10-11 8 views
0

私は主キーを必要とするカスタムCursorAdapterでGetViewにいくつかのコードを持っており、それと同じ変数を設定したいと思います。Android Custom CursorAdapter - getViewで主キーを取得しますか?

これを効率的に行うにはどうすればよいですか? GetViewは引数としてposition、convertView、およびGridViewの親を取ります。そのため、カーソルはありません。

+0

どのようなコードを使用しますか? – EpicPandaForce

答えて

0

ListViewの行番号positionを翻訳するようにアダプタに依頼してください。

私の代わりに `` CursorAdapter`のPagedListAdapter`の使用についてthis

public class MyCursorAdapter extends CursorAdapter { 
    ... 

    /** internal helper. return null if position is not available */ 
    private Cursor getCursorAt(int position) { 
     return (Cursor) getItem(position); 
    } 

    /** translates offset in adapter to id of image */ 
    public long getImageId(int position) { 
     Cursor cursor = getCursorAt(position); 

     return cursor.getLong(cursor.getColumnIndex(MY_LONG_COLUMN_NAME)); 
    } 

} 
+0

getItem(position)は、たとえ後でデータベースからオブジェクトを削除したとしても機能しますか? – CCS

+0

ListActivityが登録することができるcursoradapterのデータソースとしてcontentproviderを使用している場合、リストビューをリロードできるように変更が通知されるようにする必要があります。 – k3b

関連する問題