0

我正在尝试将数据从 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;   

     }

}
4

0 回答 0