Android 通过sql循环向TableRow动态添加多个TextView
我在这里搜索了又搜索,但我似乎无法解决这个问题。我有一个Android 通过sql循环向TableRow动态添加多个TextView,android,textview,android-linearlayout,tablerow,Android,Textview,Android Linearlayout,Tablerow,我在这里搜索了又搜索,但我似乎无法解决这个问题。我有一个滚动视图,在滚动视图中有一个线性布局,我想读取我的SQL数据库并像这样显示结果 Linear Layout ScrollView Linear Layout TableRow TextView TextView TableRow TextView Te
滚动视图
,在滚动视图
中有一个线性布局
,我想读取我的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
,但没有显示其余的,不过背景看起来已经超出了屏幕
我真的不确定我在这里做错了什么。文档说明了以下内容:
应始终将表格行
用作表格布局
的子级。如果表格行
的父级不是表格布局
,则表格行
将作为水平线性布局
如果您的目的只是使每对TextView
共享公共背景R.drawable.shape_border
,则使用嵌套的LinearLayout
代替TableRow
(TableRow
是从LinearLayout
扩展而来的)
或者,如果您绝对希望使用TableRow
的某些特定功能,则将R.id.linearCores
aTableLayout
而不是LinearLayout