android-通过sql循环将多个TextView动态添加到TableRow

android-通过sql循环将多个TextView动态添加到TableRow,第1张

概述我在这里搜索过,但似乎无法解决此问题.我有一个ScrollView,在ScrollView内是LinearLayout,我想读取我的SQL数据库并显示类似的结果;LinearLayoutScrollViewLinearLayoutTableRowTextViewTextViewTable

我在这里搜索过,但似乎无法解决此问题.我有一个ScrollVIEw,在ScrollVIEw内是linearLayout,我想读取我的sql数据库并显示类似的结果;

linear Layout    ScrollVIEw        linear Layout            tableRow               TextVIEw               TextVIEw            tableRow               TextVIEw               TextVIEw        /linear Layout    /ScrollVIEw/linearLayout

我的代码如下:

tableRow tRow;            ContextthemeWrapper ttRow = new ContextthemeWrapper(this, R.style.coretable);            linearLayout LL = (linearLayout) findVIEwByID(R.ID.linearCores);            LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);            if (cores.movetoFirst()) {                while (cores.isAfterLast() == false) {                    Log.e("CORE List", cores.getString(1));                    tRow = new tableRow(ttRow);                    tRow.setLayoutParams(lp);                    tRow.setorIEntation(tableRow.VERTICAL);                    tRow.setID(cores.getInt(0));                    tRow.setBackgroundResource(R.drawable.shape_border);                    ContextthemeWrapper newTxtA = new ContextthemeWrapper(this, R.style.coreheaderVIEw);                    TextVIEw tTextA = new TextVIEw(newTxtA);                    tTextA.setLayoutParams(lp);                    tTextA.setText(cores.getString(1) + " (Lvl " + cores.getString(2) + ")");                    tRow.addVIEw(tTextA);                    TextVIEw tTextB = new TextVIEw(coreChooser.this);                    tTextB.setLayoutParams(lp);                    tTextB.setText(cores.getString(5));                    tRow.addVIEw(tTextB);                    LL.addVIEw(tRow);                    cores.movetoNext();                }            }

在我的模拟器上,它显示了第一个tRow.addVIEw,但没有显示其他内容,但是背景显示似乎已经超过了屏幕.

我真的不确定在这里我做错了什么.

解决方法:

TableRow的文档指出以下内容:

A tableRow should always be used as a child of a tableLayout. If a tableRow‘s parent is not a tableLayout, the tableRow will behave as an horizontal linearLayout.

如果您只是想让每对TextVIEw共享公共背景R.drawable.shape_border,则可以使用嵌套的linearLayout代替tableRow(无论如何,tableRow是从linearLayout扩展的).

或者,如果您确实要使用tableRow的某些特定功能,则使R.ID.linearCores为tableLayout而不是linearLayout.

总结

以上是内存溢出为你收集整理的android-通过sql循环将多个TextView动态添加到TableRow全部内容,希望文章能够帮你解决android-通过sql循环将多个TextView动态添加到TableRow所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1120515.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存