您好,我正在尝试设置视图高度,但它在第二行抛出空指针异常。
我实际上试图将标题添加到列表活动中。为此,我的代码是:
View header= (View)getLayoutInflater().inflate(R.layout.customheader, null);
getListView.addHeaderView(header);
header.getLayoutParams().height=(int)55; //This line is throwing a null pointer exception
setListAdapter(adapter);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutParams params=new LayoutParams(-1, 55);
View header= (View)getLayoutInflater().inflate(R.layout.customheader, null);
getListView().addHeaderView(header);
getListView().setCacheColorHint(0);
getListView().setBackgroundResource(R.drawable.patterns);
setListAdapter(new Settingsadapter(this, menu));
header.setLayoutParams(params);
}
异常:E/AndroidRuntime(504):java.lang.ClassCastException:android.view.ViewGroup$LayoutParams