更改适配器的源从Sqlitedatabase而不是ArrayList

时间:2014-06-14 09:27:03

标签: android sqlite

早上好,我需要一个可能的专业提示。我有这个适配器输入ArrayList:

 public PinnedHeaderAdapter(Context context, ArrayList<String>  
 listItems,ArrayList<Integer> listSectionPos) {
    this.mContext = context;
    this.mListItems = listItems;
    this.mListSectionPos = listSectionPos;

    mLayoutInflater = (LayoutInflater) 
 mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

并在以下地方使用它:

 @Override
public Object getItem(int position) {
    return mListItems.get(position);
}

@Override
public long getItemId(int position) {
    return mListItems.get(position).hashCode();
}

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

但现在我想用这个适配器从sqlite数据库提供这个适配器:

  mHelper = new MyDbHelperContacts(getActivity());
    mDb = mHelper.getWritableDatabase();

    String[] columns = new String[] {"_id", MyDbHelperContacts.COL_USERNAME, 
    MyDbHelperContacts.COL_REALNAME,MyDbHelperContacts.COL_IMAGE1, 
    MyDbHelperContacts.COL_IMAGE2, MyDbHelperContacts.COL_EMAIL};

    mCursor = mDb.query(MyDbHelperContacts.TABLE_NAME, columns, null, null, null, 
    null, null, null);

    String[] headers = new String[] {MyDbHelperContacts.COL_USERNAME, 
    MyDbHelperContacts.COL_REALNAME};

   // mAdapter = new SimpleCursorAdapter(getActivity(), 
   android.R.layout.two_line_list_item,
   //  mCursor, headers, new int[]{android.R.id.text1, android.R.id.text2},0);


    mList.setAdapter(new simpleadapter(getActivity(), 
    android.R.layout.two_line_list_item,
            mCursor, headers, new int[]{android.R.id.text1, android.R.id.text2},0));

有什么方法可以将它们连接到togeather吗?感谢

0 个答案:

没有答案