gpt4 book ai didi

android - 使用本地 SQlite 数据库填充可扩展 ListView 的方法

转载 作者:IT王子 更新时间:2023-10-29 06:21:52 24 4
gpt4 key购买 nike

我的应用程序中有一个 sqlite 数据库。我想用它制作一个可扩展的 ListView 。

我已经确定了我应该为此采取的方法。

尝试了很多相同的教程,但找不到一个教程,其中一个是使用本地数据库填充可扩展列表。

android 站点中有一个教程,他们在其中用手机中的联系方式详细信息填充可扩展列表。他们从内容提供商那里这样做 ExpandableList2.java

所以我的问题是我是否也应该为我自己的应用程序中的数据库创建一个内容提供程序?

这是唯一的方法还是有其他更好的方法?

最佳答案

我已经创建了一个项目来试用 expandablelistview 和数据库,希望这对您有所帮助

 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;        }    }

关于android - 使用本地 SQlite 数据库填充可扩展 ListView 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6760948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com