show dialog box when 'New Game' Button is clicked
<p>i m creating a game in which i have got my code of difficulty level in a dialog box but i cant understand how to display the dialog box of difficulty level when the New Game button is Clicked. i have got my code for difficulty level in array.xml and string.xml as well.</p>

<pre><code>arrays.xml

    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;resources&gt;
        &lt;array name="difficulty"&gt;
            &lt;item&gt;@string/novice_label&lt;/item&gt;
            &lt;item&gt;@string/easy_label&lt;/item&gt;
            &lt;item&gt;@string/medium_label&lt;/item&gt;
            &lt;item&gt;@string/guru_label&lt;/item&gt;
        &lt;/array&gt;
    &lt;/resources&gt;
</code></pre>

<p>strings.xml</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;resources&gt;
    &lt;string name="app_name"&gt;Brain Training Game&lt;/string&gt;
    &lt;string name="main_title"&gt;Brain Training Game&lt;/string&gt;
    &lt;string name="new_game_label"&gt;New Game&lt;/string&gt;
    &lt;string name="continue_label"&gt;Continue&lt;/string&gt;
    &lt;string name="about_label"&gt;About&lt;/string&gt;
    &lt;string name="exit_label"&gt;Exit&lt;/string&gt;
    &lt;string name="about_title"&gt;About Brain Training Game&lt;/string&gt;
    &lt;string name="about_text"&gt;\
    Brain Training Game is a logic-based number placement puzzle.
    Starting with a partially completed 9x9 grid, the
    objective is to fill the grid so that each
    row, each column, and each of the 3x3 boxes
    (also called &lt;i&gt;blocks&lt;/i&gt;) contains the digits
    1 to 9 exactly once&lt;/string&gt;
    &lt;string name="new_game_title"&gt;Difficulty&lt;/string&gt;
    &lt;string name="novice_label"&gt;Novice&lt;/string&gt;
    &lt;string name="easy_label"&gt;Easy&lt;/string&gt;
    &lt;string name="medium_label"&gt;Medium&lt;/string&gt;
    &lt;string name="guru_label"&gt;Guru&lt;/string&gt;
    &lt;/resources&gt;
</code></pre>

<p>Btg.Java</p>

<pre><code>package org.example.btg;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;

import android.os.Bundle;

public class BrainTrainingGame extends Activity implements OnClickListener {
    protected static final String TAG = null;
    /** Called when the activity is first created. */
    @SuppressWarnings("null")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        View newButton = findViewById(R.id.new_button);
        newButton.setOnClickListener(this);
        View continueButton = findViewById(R.id.continue_button);
        continueButton.setOnClickListener(this);
        View aboutButton = findViewById(R.id.about_button);
        aboutButton.setOnClickListener(this);
        View exitButton = findViewById(R.id.exit_button);
        exitButton.setOnClickListener(this);
    }
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.about_button:
        Intent i = new Intent(this, About.class);
        startActivity(i);
        break;

        case R.id.exit_button:
        finish();
        break;

        case R.id.new_button:
        openNewGameDialog();
        break;
        }
    }


    public void openNewGameDialog() {
        new AlertDialog.Builder(this);
        setTitle(R.string.new_game_title);
        setItems(R.array.difficulty,new DialogInterface.OnClickListener()
        new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialoginterface, int i) {
                startGame(i);
            }
        })
        .show();
}

    private void startGame(int i){
        Log.d(TAG, "clicked on " +i);

    }
}
</code></pre>

<p>thanks for help in advance ;)</p>
