Displaying alert dialog box repeatedly
<p>In my android application, I use countTokens() method. If the count is greater than 1, It will display an alert dialog box with two buttons YES or NO. When the user clicks the YES button, it immediately get out of the loop. If the user clicks NO button, it will display the next token again with those two buttons and so on..</p>

<p>I wrote the following code for this. But the problem is, It didn't consider which button the user clicked. It means it display the alert dialog box even if the user clicks YES button.</p>

<pre><code>while ((line = reader.readLine()) != null) 
{
//sb.append(line + "\n");
final StringTokenizer st=new StringTokenizer(line);
count=st.countTokens();
Toast.makeText(getBaseContext(), count+" names found", Toast.LENGTH_SHORT).show();
if (count&gt;1)
{
do{
if(alc)
{
r_code=st.nextToken();
AlertDialog.Builder alert=new AlertDialog.Builder(Fetch.this);
alert.setTitle(count+" records found for "+rytname.getText().toString());
alert.setMessage("Are you sure want to search for "+r_code+"?");
alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
  ff=1;
  alc=false;
}
});

alert.setNegativeButton("NO", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
  // TODO Auto-generated method stub
  ff=0;
}
});
alert.show();
}while(ff==0);
}
else
{
r_code=st.nextToken();
ff=1;
alc=true;                           
}
}
</code></pre>

<p>I'm trying this over 2 hours, Somebody help please..</p>

<p>I need to display the dialog box next time only if the user clicks the NO button. Thanks in advance</p>
