[英]Dynamic table layout
我想在表行中顯示來自數據庫的一些注釋,可以從數據庫中獲取帶有注釋的數據,但是在我的活動中,頁面標題未顯示任何內容,但我找不到錯誤:小號
這是Java部分:
public class PIComments extends Activity{
public static final String EXTRA_IDPI="EXTRA_IDPI";
TableLayout messagesTable;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.picomments);
messagesTable = (TableLayout)findViewById(R.id.commentTable);
long PIID = getIntent().getLongExtra(EXTRA_IDPI, 0);
if(PIID>0){
ArrayList<CommentMsg> comments = CommentMsg.getPIComments(PIID);
if(comments != null){
for(int i=0; i<comments.size(); i++) {
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
tr.setId(i);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to house the name of the province
TextView login = new TextView(this);
login.setId(i);
login.setText(comments.get(i).getMsg());
//login.setText(comments.get(i).getAuteur());
login.setTextColor(Color.BLACK);
login.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(login);
// Add the TableRow to the TableLayout
messagesTable.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
else{
Dialog d = new Dialog(PIComments.this);
d.setTitle("No comments for the moment ... ");
d.show();
}
}
}
}
並且有xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffccd0"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="#ffb0b6"
android:text="Comments"
android:textColor="#b3000d"
android:textSize="26dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/ll_country"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="@+id/ScrollView11"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/commentTable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" >
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
知道了,每個LayoutParams應該是android.widget.TableRow.LayoutParams的,除了提供給tl.addView(...)的一個。
/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
//tr.setBackgroundResource(R.drawable.sf_gradient_03);
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
要么
我有同樣的問題,然后刪除
textView.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
在每個textview中,都會顯示一些內容。
要么
將您的textView顏色設置為
textView.setTextColor(Color.WHITE);
您的背景可能會是黑色以及文字顏色:)
但是仍然不能幫忙,請參考這個非常好的教程,可能您會丟失一些東西。 Android中的動態TableLayout
我希望這能幫到您。
謝謝 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.