我的数据库中有一张表:
piecetable (description, imgdescription, imgpiece, codsag, codoe, n, csct, a, b, cod_auto, cod_brand)
我有一个简单的 GridView,它有八个固定列,称为 piecedatagridview
我想从数据库中获取数据并放入这个 GridView。
我该怎么做?
两列必须包含从 imgdescription 和 imgpiece 中获取的两张图像,可在 drawable
文件夹中找到。
我如何首先将粗体标题列加载到 GridView 中,然后从数据库中加载行?
代码:
<GridLayout
android:layout_width="1172dp"
android:layout_height="290dp"
android:layout_row="2"
android:layout_column="0">
<GridView
android:layout_width="wrap_content"
android:layout_height="263dp"
android:id="@+id/tabellaPezzi"
android:layout_row="0"
android:layout_column="0"
android:numColumns="8"
android:smoothScrollbar="false" />
</GridLayout>
最佳答案
我将用另一个问题来回答您的问题:您需要 GridList 有什么用?当将相同的元素类型表示为类似网格的布局时,使用 GridList;在你的情况下,一个 ListView 包装了你需要显示的所有项目似乎是更好的选择。 对于 drawables 部分,将 res/drawable 文件夹的资源 int 地址(即 R.drawable.drawable_name)保存到您的数据库中,然后在构建行时获取实际图像。
关于Android Studio 从带有 sqlite 的数据库到 GridView 和标题列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31870112/