android在Fragment中ListView如何初始化
publicclassMyListViewextendsListView这是我自定义的一个类去继承了ListViewpublicclassForumsFragmentex...
public class MyListView extends ListView这是我自定义的一个类去继承了ListView
public class ForumsFragment extends Fragment在这个Fragment中要初始化ListView
代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_contacts, container,
false);
initViews(view);
}
/**
* 给控件初始化
*/
private void initViews(View view) {
myListView = (MyListView) view.findViewById(R.id.lv_forum);
}
myListView定义成了成员变量
运行的时候报了
java.lang.ClassCastException: android.widget.ListView cannot be cast to com.special.view.MyListView
我想问应该如何对ListView进行初始化。 展开
public class ForumsFragment extends Fragment在这个Fragment中要初始化ListView
代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_contacts, container,
false);
initViews(view);
}
/**
* 给控件初始化
*/
private void initViews(View view) {
myListView = (MyListView) view.findViewById(R.id.lv_forum);
}
myListView定义成了成员变量
运行的时候报了
java.lang.ClassCastException: android.widget.ListView cannot be cast to com.special.view.MyListView
我想问应该如何对ListView进行初始化。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询