0

I would like to add a AlertDialog after clicking on a button (cf below) that starts an activity to choose a picture.

I click the button to choose a picture. I choose the picture and I want to make display my AlertDialog after choosing the picture.

    final Button myButton = (Button) findViewById(R.id.button);
    myButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MyActivity.this, OpenImageActivity.class);
            startActivity(intent);
        }
    });

How can i make visible my AlertDialog?

Thanks.

4

3 回答 3

1

First , you have to sent intent like this

final Button myButton = (Button) findViewById(R.id.wall);
myButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentCROP = new Intent(MyActivity.this, OpenImageListActivity.class);
        //startActivity(intentCROP);
        startActivityForResult(intentCROP, 1);
    }
});

then while you click on your list item on target activity

    @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    Intent intent = new Intent();
    intent.putExtra("code", "response");
    setResult(RESULT_OK, intent);
    finish();

}

Now, back to first activity

    @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {


                            // here you can show your alert dialog


        }
    }

}
于 2013-10-01T09:42:01.327 回答
0
AlertDialog.Builder alert;
alert = new AlertDialog.Builder(this);

&在您的点击方法中执行此操作

alert.setMessage("Title").setCancelable(false)
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                //do your work      

            }
        })
        .setNegativeButton("No", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                dialog.cancel();
            }
        });

         AlertDialog alert1 = alert.create();  
         alert1.show();
于 2013-10-01T09:31:59.877 回答
0

你可以做这样的事情

mButton1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

     confirmdialog();
}
 });

现在确认对话框方法

protected void confirmdialog() {
    // TODO Auto-generated method stub
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);

    // Setting Dialog Title
    alertDialog.setTitle("Confirm Delete...");

    // Setting Dialog Message
    alertDialog.setMessage("Delete from History?");



    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {
                         //whatever you want to do
        }
    });

    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
                         //cancel the dialog
            dialog.cancel();
        }
    });


    alertDialog.show();
}
于 2013-10-01T10:07:25.457 回答