4
这里是我添加列表到我的清单fragmet代码:广东话添加HeaderView到ListFragment
public void onAttach(Activity activity) {
super.onAttach(activity);
System.err.println("Fragment Attach");
String[] MyList = {"Item 1","Item 2","Item 3","Item 4","Item 5"};
System.err.println("File Row ID" + Integer.toString(R.layout.file_row));
ArrayAdapter<String> aa = new ArrayAdapter<String>(getActivity(), R.layout.file_row, MyList);
//Trying to add a Header View.
TextView tv = (TextView) activity.findViewById(R.layout.file_row);
tv.setText(R.string.FileBrowserHeader);
this.getListView().addHeaderView(tv);
//Setting the adapter
setListAdapter(aa);
}
然而行this.getListView()addHeaderView(TV);给我的错误
06-11 15:24:46.110:ERROR/AndroidRuntime(8532):java.lang.IllegalStateException:致尚未创建
而且程序崩溃的内容视图。
谁能告诉我我做错了什么?
哇!谢谢,虽然我不得不改变其中的一行代码:\t \t // TextView tv =(TextView)getActivity()。findViewById(R.layout.file_row);到这一行 \t \t TextView tv = new TextView(getActivity());然后它感谢! – aarelovich 2011-06-11 19:25:24