1
\$\begingroup\$

I am newbie Android developer, and I am starting out with a simple Sudoku game. The problem I am facing right now is that I have my game showing on a dedicated Activity, which is displaying a custom View class. I have the code within the onDraw function. Now I want to show a custom keypad view, which is a separate class extending View, whenever a user clicks on a block in the Sudoku grid.

I am extremely confused as to how I should go about doing this. I am reluctant to create a dedicated activity for just this keypad, and want to show this keypad over the Sudoku grid view that the activity is currently displaying.

The activity is using setContentView(myCustomGridViewClass) to show the grid. Now I want something to the equivalent of

onTouch -> setContentView(myCustomKeypadView), though this should appear over the previous view.

I have tried reading about the LayoutInflater, but did not understand how to use it to show the keypad within this same activity. This is probably a very noob question, but any help, including any other questions, or sources I could refer to for an answer would be highly appreciated.

Regards,

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

You could place both views in a FrameLayout or a RelativeLayout and control the keypad's visibility (http://developer.android.com/reference/android/view/View.html#setVisibility(int)) when needed.

Change setContentView(myCustomGridViewClass) to setContentView(R.layout.id_of_my_layout), then write id_of_my_layout.xml that contains the layout (more help here http://developer.android.com/guide/topics/ui/declaring-layout.html).

Make sure to add your keypad view after the game view in your layout xml, otherwise the game view will be placed on top of it and you'll never see the keypad :)

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the response. I am working on this solution, and I think I should be able to make this work. Marking this as the answer, coz I can see how this will work. Thanks again. \$\endgroup\$
    – kvnam
    Commented Apr 15, 2013 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .