java安卓表格布局。addView()实际上不起作用
我试图用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);
什么都没发生。在这一行之后,应用程序什么也不做
希望有人能告诉我我的错误
# 1 楼答案
您不需要将视图添加到TableRow,只需将视图添加到TableLayout。试试这个:
}