【发布时间】:2015-01-27 04:26:00
【问题描述】:
我正在尝试使用 addView 方法为我的 TableLayout 填充一些视图。
这是我尝试做的:
private void createNewTable(){
tableLayout = (TableLayout) getView().findViewById(R.id.tableLayout1);
for(int i = 0; i < objectList.size(); i++){
if(objectList.get(i).getType() == 0){
tableLayout.addView(createLocationObjectInTable((LocationObject)objectList.get(i)), i);
}
}
}
还有 createObjectInList 方法:
private View createLocationObjectInTable(LocationObject locObject) {
TableRow tr = new TableRow(getActivity());
View v = LayoutInflater.from(getActivity()).inflate(R.layout.view_layout, tr, false);
TextView textViewCityName = (TextView) v.findViewById(R.id.textView_City_Name);
TextView textViewCityProvider = (TextView) v.findViewById(R.id.textView_City_Provider);
textViewCityName.setText(locObject.getTitle());
textViewCityProvider.setText(locObject.getSubTitle());
return v;
}
但是视图没有显示在 tableLayout 中。 Logcat 没有给我任何错误信息,当我尝试在该行之后做一些事情时
tableLayout.addView(createLocationObjectInTable((LocationObject)objectList.get(i)), i);
什么都没发生。该应用程序在此行之后什么都不做。
希望有人能告诉我我的错误吗?
【问题讨论】:
-
您不应该从 createLocationObjectInTable 方法返回 TableRow 视图 (tr) 而不是膨胀的 View v?
-
即使我返回 tr,视图也不显示。我从 AsyncTask 中调用方法 createNewtable(),可能这会导致一些问题?
标签: java android fragment tablelayout