public class MainActivity extends Activity implements OnClickListener{ TextView tvStart; int right = 21; int left = -1; int currentNum; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvStart = (TextView) findViewById(R.id.tvStart); tvStart.setOnClickListener(this); } @Override public void onClick(View v){ String p = Integer.toString(currentNum); switch(v.getId()){ case R.id.tvStart: AlertDialog.Builder aDb = new AlertDialog.Builder(MainActivity.this); View Builder = getLayoutInflater().inflate(R.layout.activity_main,null); currentNum = (left + right) / 2; aDb.setMessage("Ваше число " + currentNum); aDb.setCancelable(false); aDb.setPositiveButton("<", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which){ right = currentNum; } }); aDb.setNeutralButton("=", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which){ Toast.makeText(MainActivity.this, "Угадали", Toast.LENGTH_LONG).show(); left = 0; right = 20; } }); aDb.setNegativeButton(">", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which){ left = currentNum; if(currentNum>19){ Toast.makeText(MainActivity.this, "Ошибочка", Toast.LENGTH_LONG).show(); } } }); AlertDialog aD = aDb.create(); aD.show(); break; } The principle of work: we made a number from 0 to 20 (in the mind). Click on the TextView, a dialog box with the inscription: "your number N?" Click the "less", "more", "equal" button, until we press "=". But the problem is that you have to click on TextWiew every time.
How to make so that after clicking of the button the dialog box was caused itself?