Domanda

I know how to pass data using Intents and I know how to create AlertDialog, but is it possible to start alert dialog and pass data using intents?

final String[] items1 = {"ringtone", "poruka", "alarm"};
            final AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
            builder1.setTitle("Postavi kao");
            builder1.setItems(items1, new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {

                    if (which == 0) {
                    //  button 1
                    }
                if (which == 1){
                    // button 2
                }
                if (which ==2 ){
                // button 3
                }
                }

            });
            builder1.create();
 builder1.show();

And my code to pass intents

 Intent i0=new Intent(context, Rm.class);
                     if (i0 != null){
                     i0.putExtra("NAME", "Traffic mix!");
                     int res = R.raw.s1thrafficmix;
                     i0.putExtra("PATH", res);
                     i0.putExtra("FILE", "Traffic mix.mp3");
                     ((Activity)context).startActivity(i0);
                     }

If yes, how can I do it? Put the alertDialog in other activity or?

È stato utile?

Soluzione

class A{

        static int num = 0; 

        public void setNum(int number){

            num = number 

        }

    }

    class B{
        public static void main(){
            A obja = new A();
            obja.setNum(3);

        } 
    }

As soon as you do the operation in class B you can use the num variable in class A.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top