我正在将我的应用程序从 AsyncTasks 移植到 Fragments。
但是如何访问我的片段中的 listView (id: list) 元素?
class MyFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.list_fragment, container, false);
ListView listView = getListView(); //EX:
listView.setTextFilterEnabled(true);
registerForContextMenu(listView);
return v;
}
}
xml:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
前任:
Caused by: java.lang.IllegalStateException: Content view not yet created