cairunbo
@TianCheng
2016-04-28 10:05
采纳率: 92.9%
浏览 1.2k
已采纳

关于安卓的SQLite问题

大神好,小弟学习时遇到这个问题,不知道该怎么解决
图片说明
我是想要在一个Fragment页面里动态加载ListView,写了一个自定义的Adapter
在 onActivityCreated里面写了
adapter=new FragmentRecordAdapter(this,start, end);
listView_data.setAdapter(adapter);

在Adapter里面写了
public class FragmentRecordAdapter extends BaseAdapter {
AddDAO2 adao;
FragmentRecord f;
Cursor cursor;

public FragmentRecordAdapter(FragmentRecord fragmentRecord, String start,String end) {
    // TODO Auto-generated constructor stub
    this.f=fragmentRecord;
    adao = new AddDAO2(f);
    cursor = adao.queryAllDetail(start, end);
}

@Override
public int getCount() {
    return cursor.getCount();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@SuppressLint("InflateParams") 
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view = null;
    if (convertView != null) {
    view = convertView;//复用了回收的view 只需要直接作内容填充的修改就好了
    } else {
    view = LayoutInflater.from(null).inflate(R.layout.f_record_detail_lv_item_2, null);
    //没有供复用的view 按一般的做法新建view
    TextView tv01 = (TextView) view.findViewById(R.id.tv01);
    TextView tv02 = (TextView) view.findViewById(R.id.tv02);
    TextView tv03 = (TextView) view.findViewById(R.id.tv03);
    TextView tv04 = (TextView) view.findViewById(R.id.tv04);
    cursor.moveToPosition(position);
    tv01.setText(cursor.getString(cursor.getColumnIndex(ActionConstants.record.SportType)));
    tv02.setText(cursor.getString(cursor.getColumnIndex(ActionConstants.record.FitnessPart)));
    tv03.setText(cursor.getString(cursor.getColumnIndex(ActionConstants.record.FitnessContent)));
    tv04.setText(cursor.getString(cursor.getColumnIndex(ActionConstants.record.Time)));
    }
    return view;
}

}
在AddDAO2里面:
public class AddDAO2 {
SQLiteDatabase db;

public AddDAO2(FragmentRecord f) {
    // TODO Auto-generated constructor stub
    db = new ActionDataHelper(null, f).getWritableDatabase();
}

想不明白该怎么解决,求大神帮助!谢谢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • bealing
    xSeeker~ 2016-04-28 10:31
    已采纳

    我看你的log,错误的地方已是insert语句add附近,add是SQLite的关键字,你用add作为表名,存在歧义,建议将表名换成合适的

    点赞 评论
  • dongfeng9ge
    东风玖哥 2016-04-29 07:31

    建议使用GreenDao框架

    点赞 评论

相关推荐