我正在创建一个新的 Tab 界面,对于每个选项卡,我都具有如下功能:
public class ClassViewFragment extends Fragment {
ListView classListView = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.class_view, container, false);
classListView = (ListView) findViewById(R.id.classList);
return rootView;
}
}
但我得到 cannot resolve method findViewById
同样在另一个地方我也无法使用runOnUiThread
并得到 Error:(88, 29) error: cannot find symbol method runOnUiThread(<anonymous Runnable>)
我知道如果我的类(class)是从 Activity
扩展的,这些会很好用但它是一个标签 fragment ,所以我该如何使用这个功能?
最佳答案
你需要
classListView = (ListView) rootView.findViewById(R.id.classList);
因为那是你关心的观点
要获得 runOnUiThred,您需要执行 getActivity().runOnUiThread
关于android - 在 Fragment 中使用 findViewById,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28052862/