我想用一些視圖填充我的TableLayout與方法addView。Android的TableLayout.addView()不真的工作
這是我嘗試做:
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);
什麼happend後做的東西。這條線後,該應用程序什麼都不做。
希望任何人都可以告訴我我的錯誤?
你不是應該返回從你createLocationObjectInTable方法而不是膨脹的視圖V的的TableRow視圖(TR)? – 2015-01-26 20:26:08
即使我返回tr,視圖也不會顯示。我從AsyncTask調用createNewtable()方法,也許這會導致一些問題? – RyuZz 2015-01-26 20:42:07