我有一个activity.java文件,其中有我的setContentView(R.layout.x);现在,我有一个文件,我必须y.xml在我的视图Linear Layout中附加一个onclick()方法。附件onclick()必须在我的activity.java文件中,如何包含y.xml.
我试过这个,
1. layout = (LinearLayout) findViewById(R.layout.y);
eView = (EditText)layout. findViewById(R.id.editview);
2. eView = (EditText)findViewById(R.id.editview);
但两者都给出了我的null pointer exception,我如何包括我的editText
更新
final LayoutInflater lyInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
showLinearLayout = (LinearLayout) lyInflater.inflate(R.layout.y, null);
showView = (EditView) showLinearLayout.findViewById(R.id.edittext);