protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
LinearLayout relativeLayout = (LinearLayout) findViewById (R.id.layout456);
ImageView imgApple2 = new ImageView (this);
imgApple2.setImageResource (R.drawable.ic_launcher);
relativeLayout.addView (imgApple2);
LayoutInflater factorys = LayoutInflater.from (MainActivity.this);
final View textEntryView = factorys.inflate (R.layout.layout1, null);
/ / LinearLayout linearLayout = (LinearLayout) textEntryView
. / / FindViewById (R.id.layout1);
/ / RelativeLayout.addView (linearLayout);
EditText editText1 = (EditText) textEntryView
. FindViewById (R.id.editText1);
relativeLayout.addView (editText1);
}
I want to get in the top layout1 inside another layout controls editText1, added to the main layout, Why run prompted to null.
If I like to write the following, and no errors, and successfully added
LinearLayout linearLayout = (LinearLayout) textEntryView
. FindViewById (R.id.layout1);
relativeLayout.addView (linearLayout);
The above is the full join another layout, all I want is a control layout. Solved, thank you! !
Reply:
The landlord, in a word, while any child controls can only exist in a parent control layout.
So editText1 as layout1 child controls, can only exist in layout1, and it can only be the son layout1, this kinship can not be easily changed while layout1 because it is the entire layout, which can be layout456 its son.
No comments:
Post a Comment