我知道如何使用Intents传递数据,我知道如何创建AlertDialog,但是是否可以启动警报对话框并使用意图传递数据?
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();
我传递意图的代码
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);
}
如果是,我该怎么办?将alertDialog放入其他活动或?
答案 0 :(得分:1)
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);
}
}
只要在B类中执行操作,就可以使用A类中的num变量。