title: android getting variables to constructor of custom view
body: <p>android newbie here.</p>
  
  <p>My first game involves a custom view, which is going to draw a game board and some scoreboards on the screen. I need to know how many players there are in order to get the number of scoreboards up, and I need this to be in known in the constructor of the custom view, so that appropriate variables are initialised on time.</p>
  
  <p>My current implementation is like this, is this the correct way to get variables into the custom view constructor?...</p>
  
  <p>I instantiate the custom view from my activity like this:</p>
  
  <pre><code>numPlayers=2;
  setContentView(R.layout.gamescreen);
  mBoardView = (BoardView) findViewById(R.id.board_view);
  </code></pre>
  
  <p>And in the custom view constructor:</p>
  
  <pre><code>public BoardView(Context context, AttributeSet attrs){
              super(context, attrs);
  vNumPlayers = ((GuappsXOMainGame)getContext()).getNumP(); 
  </code></pre>
  
  <p>That's how I have it now and it seems to work well enough, but is it better to be doing something along the lines of the answer to this question:?</p>
  
  <p><a href="https://stackoverflow.com/questions/5816001/androidhow-to-instantiate-my-custom-view-with-attributeset-constructor">android:how to instantiate my custom view with attributeset constructor</a></p>