setContentView gives an exception

断了今生、忘了曾经 提交于 2019-12-11 16:24:59

问题


In my android app I set

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN ); Then my touch screen event doesnt’ work any more.

Further Explaining,

I have a button and onClick it changes the contentView by setContentView(R.layout.choose_player);. It works fine. But if you take the focus to the button by the trackball(making it yellow) and tap on it, it gives the exception.

java.lang.IllegalArgumentException: parameter must be a descendant of this view

public void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  requestWindowFeature(Window.FEATURE_NO_TITLE);     
  this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                           WindowManager.LayoutParams.FLAG_FULLSCREEN);         
  setContentView(R.layout.main1);    
} 

public void onClick(View v) {    
  setContentView(R.layout.main2); 
}

回答1:


you use setContentView only once in your 'onCreate' method, in general for the main window (one Activity = 1 view)

in your case you should probably change your Background..




回答2:


i cant understand properly first. I think you may be using setContentView method multiple times. one is to set the layout on the view. another one inside the click event. right? that not works. use that method once to set the layout. on click event you have to do your tasks on the views inside the layout. hope it helps. please post some code snippets for the perfect answers.



来源:https://stackoverflow.com/questions/2863015/setcontentview-gives-an-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!