user1285707
user1285707

Reputation:

how to remove progress dialog When value is selected from it?

final CharSequence[] items = {"Red", "Green", "Blue"}

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("Pick a color");

builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int item) {

        Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
    }
});

AlertDialog alert = builder.create();

when i select a value from(Red,green,Blue) it should remove how it will.please help.

Upvotes: 0

Views: 120

Answers (3)

Bhaskar Reddy
Bhaskar Reddy

Reputation: 480

Use below code it will work.

public class TestingActivity extends Activity {

    AlertDialog alert;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final CharSequence[] items = { "Red", "Green", "Blue" };

        final AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle("Pick a color");



        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int item) {

                Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                        dismiss();
            }

        });
        alert = builder.create();

        alert.show();
    }

    private void dismiss() {
        alert.dismiss();

    }
    }

Upvotes: 0

user370305
user370305

Reputation: 109237

Try this,

final CharSequence[] items = {"Red", "Green", "Blue"}   
final AlertDialog alert = null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);  
builder.setTitle("Pick a color");    
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {  
    public void onClick(DialogInterface dialog, int item) {

        Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
     alert.dismiss();
    }
}); 
 alert = builder.create();
 alert.show();

Upvotes: 0

MAC
MAC

Reputation: 15847

builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int item) {  
    //Here you gets dialog as argument

        dialog.dismiss(); <---------
    }
});

Upvotes: 2

Related Questions