方法来填充扩展列表视图与当地SQLite数据库视图、方法来、当地、数据库

2023-09-06 03:15:56 作者:南城挽歌

我在我的应用程序中的SQLite数据库。我想提出一个可扩展的列表视图这一点。

I have a sqlite database in my application. I want to make an expandable list view with that.

我固定的,我应该采取的办法。

I am fixed with the approach I should take for that.

尝试了很多找一个教程一样,但无法找到一个单一的,其中一个是填充扩展列表与本地数据库。

Tried a lot to find a tutorial for the same, but could not find a single one, where one is populating the Expandable list with the local database.

目前在android网站,他们正在填补的扩展列表的详细联系方式在手机这一块教程。他们从内容提供商这样做 ExpandableList2.java

There is this one tutorial in the android site where they are filling the expandable list with the Contact detail in the phone. They are doing this from the content provider ExpandableList2.java

所以我的问题是,我应该还可以创建一个内容提供商我的数​​据库是在我自己的应用程序?

So my question is should I also create a content provider for my database which is inside my own application ?

这是唯一的方法,或是否有任何其他更好的?

Is this the only approach or is there any other better one?

推荐答案

我已经创建了一个项目尝试expandablelistview和数据库,希望这有助于

I had created a project to try out expandablelistview and database, hope this helps


 final class ExpAdapter extends CursorTreeAdapter {
        LayoutInflater mInflator;

        public ExpAdapter(Cursor cursor, Context context) {
            super(cursor, context);
            mInflator = LayoutInflater.from(context);
        }

        @Override
        protected void bindChildView(View view, Context context, Cursor cursor,
                boolean isLastChild) {
            TextView tvChild = (TextView) view.findViewById(android.R.id.text1);
            tvChild.setText(cursor.getString(cursor
                    .getColumnIndex(DBHelper.COL_TABLE_CHILD_NAME)));
        }

        @Override
        protected void bindGroupView(View view, Context context, Cursor cursor,
                boolean isExpanded) {
            TextView tvGrp = (TextView) view.findViewById(android.R.id.text1);
            tvGrp.setText(cursor.getString(cursor
                    .getColumnIndex(DBHelper.COL_TABLE_MAIN_NAME)));
        }

        @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) {
            int groupId = groupCursor.getInt(groupCursor
                    .getColumnIndex(DBHelper.COL_ID));
            return aDBHelper.getChildCursor(groupId);
        }

        @Override
        protected View newChildView(Context context, Cursor cursor,
                boolean isLastChild, ViewGroup parent) {
            View mView = mInflator.inflate(
                    android.R.layout.simple_expandable_list_item_1, null);
            TextView tvChild = (TextView) mView
                    .findViewById(android.R.id.text1);
            tvChild.setText(cursor.getString(cursor
                    .getColumnIndex(DBHelper.COL_TABLE_CHILD_NAME)));
            return mView;
        }

        @Override
        protected View newGroupView(Context context, Cursor cursor,
                boolean isExpanded, ViewGroup parent) {
            View mView = mInflator.inflate(
                    android.R.layout.simple_expandable_list_item_1, null);
            TextView tvGrp = (TextView) mView.findViewById(android.R.id.text1);
            tvGrp.setText(cursor.getString(cursor
                    .getColumnIndex(DBHelper.COL_TABLE_MAIN_NAME)));
            return mView;
        }

    }