我有一个使用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检查版本如下:if api level> = 11使用新版本,否则使用旧版本?
答案 0 :(得分:3)
试试SimpleCursorAdapter from the support class。它像API 11+版本一样使用,并且已经向后兼容。
您已经下载了支持库(如果您还没有真的),那么您只需要更改导入:
import android.support.v4.widget.SimpleCursorAdapter;
答案 1 :(得分:2)
if (Android.os.Build.VERSION.RELEASE==Build.VERSION_CODES.HONEYCOMB){
...
} else {
...
}