Java 如何在android中设置customListView?
我一直在遵循一个教程,但我认为它已经过时了,我已经设置了listView工作所需的一切,但当我运行它时,它说-Java 如何在android中设置customListView?,java,android,listview,nullpointerexception,android-arrayadapter,Java,Android,Listview,Nullpointerexception,Android Arrayadapter,我一直在遵循一个教程,但我认为它已经过时了,我已经设置了listView工作所需的一切,但当我运行它时,它说- java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at youknow.smscontrol.jason.testexpandiblelistview.CoustmListViewSettup.getView(CoustmListViewSettup.java:29)
以下是我的XML:
这是我的customListViewSetup类:
class CustomListViewSetup extends ArrayAdapter<String>{
public CustomListViewSetup(Context context, String[] CMDList){
super(context,R.layout.coustom_list_item ,CMDList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater CMDlistInflater = LayoutInflater.from(getContext());
View coustomView = CMDlistInflater.inflate(R.layout.coustom_list_item, parent, false);
String CurrentCMDlistitem = getItem(position);
LINE 29>> TextView CMDlist = (TextView) convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow = (ImageView) convertView.findViewById(R.id.LaunchArrow);
CMDlist.setText(CurrentCMDlistitem);
CMDLaunchArrow.setBackgroundResource(R.drawable.item_launch);
return coustomView;
}
}
class CustomListViewSetup扩展了ArrayAdapter{
公共CustomListViewSetup(上下文上下文,字符串[]CMDList){
超级(上下文,R.layout.coustom\u列表项,CMDList);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutInflater CMDlistInflater=LayoutInflater.from(getContext());
View-coustomView=CMDlistInflater.inflate(R.layout.coustom\u列表\u项,父项,false);
字符串CurrentCMDlistitem=getItem(位置);
第29行>>TextView CMDlist=(TextView)convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow=(ImageView)convertView.findViewById(R.id.LaunchArrow);
CMDlist.setText(CurrentCMDlistitem);
CMDLaunchArrow.setBackgroundResource(R.drawable.item_launch);
返回视图;
}
}
提前谢谢你
LayoutInflater CMDlistInflater = LayoutInflater.from(getContext());
View coustomView = CMDlistInflater.inflate(R.layout.coustom_list_item, parent, false);
拆下此线路更换线路
TextView CMDlist = (TextView) convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow = (ImageView) convertView.findViewById(R.id.LaunchArrow);
借
LayoutInflater CMDlistInflater = LayoutInflater.from(getContext());
View coustomView = CMDlistInflater.inflate(R.layout.coustom_list_item, parent, false);
TextView CMDlist = (TextView) convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow = (ImageView) convertView.findViewById(R.id.LaunchArrow);
TextView CMDlist = (TextView) coustomView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow = (ImageView) coustomView.findViewById(R.id.LaunchArrow);