2

我有一个使用SimpleCursorAdapter

API level 9 当我想使用时,我有最小值,SimpleCursorAdapter我使用以下构造函数:

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)

但后来我得到消息,这是不推荐使用的。

所以我将其更改为较新的版本:

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)

但是我的最低 API 级别应该是 11,但我不想更改它。

是否可以让 android 检查版本,例如:如果 api level >= 11 使用新版本,否则使用旧版本?

4

2 回答 2

3

尝试支持类中的 SimpleCursorAdapter。它与 API 11+ 版本一样使用,并且已经向后兼容。

很可能你已经下载了支持库(如果你真的没有下载的话),所以你只需要更改导入:

import android.support.v4.widget.SimpleCursorAdapter;
于 2012-09-24T18:03:06.147 回答
2
if (Android.os.Build.VERSION.RELEASE==Build.VERSION_CODES.HONEYCOMB){
...
} else {
...
}
于 2012-09-24T18:05:49.010 回答