SimpleCursorAdapter()已弃用,我该如何替换它?

时间:2013-04-21 21:20:07

标签: android-sqlite simplecursoradapter

我正在尝试将SQLite中的数据显示到列表视图中。我尝试使用构造函数SimpCursorAdapter(),但它说它已被弃用,我不能使用它。任何人都不知道如何做到这一点,没有任何其他方式???以下是我的代码:

public class JournalsTab extends Fragment {
 private SimpleCursorAdapter dataAdapter;
     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
         LinearLayout l2 = (LinearLayout) inflater.inflate(R.layout.journal, container, false);

         BalanceApp myapp= (BalanceApp) getActivity().getApplicationContext();
            DataSource datasource = myapp.datasource;
            datasource.open();

            Cursor cursor = datasource.fetchAllEntries();
            int[] to = {R.id.textView1, R.id.textView2, R.id.textView3, R.id.text4};

            dataAdapter = new SimpleCursorAdapter(this, R.layout.journal,cursor, datasource.columns, to);   //this gives error

            ListView listView = (ListView)l2.findViewById(R.id.listView1);
                listView.setAdapter(dataAdapter);


            return l2;   

     }

}

0 个答案:

没有答案