我想在动态TextView
中显示来自数据库的文本。我创建了动态布局尽可能多的表格,我还动态创建了TextView
。
在下面提到的日志中获取文本,但它没有显示在TextView
中。
这是我的代码:
for(int i=0;i<count;i++){
LinearLayout linear=new LinearLayout(this);
linear.setId(100+i);
LayoutParams pram=new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
linear.setLayoutParams(pram);
linear.setOrientation(LinearLayout.HORIZONTAL);
for (int j = 0; j < countcolumn.size(); j++) {
TextView view = new TextView(this);
Log.i(ListViewDisplay.class.getSimpleName(),
"column values that is want to set "
+ columnValues.get(j));
String temp=columnValues.get(j).toString();
view.setText(temp);
view.setTextSize(20);
view.setId(j + 11);
view.setWidth(200);
view.setHeight(100);
view.setPadding(10, 10, 10, 10);
linear.addView(view);
}
}
答案 0 :(得分:0)
您需要设置TextViews'LayoutParams
才能正确绘制它们。
尝试在linear.addView(view)
:
view.setLayoutParams(new LayoutParams(200, 100));
您也可以删除这些行,因为它们将由LayoutParams
:
view.setWidth(200);
view.setHeight(100);