我想在表格中顯示來自我的數據庫的一些評論,從評論數據庫中獲取數據是可以的,但在我的活動中沒有任何內容顯示我的頁面的標題,我只是可以「找不到錯誤:S動態表格佈局
下面是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>
如果我的回答可以幫助你,那麼請不要忘記接受我的回答,並投票給我也會非常感激。謝謝:) – SALMAN 2012-07-22 15:06:13