我用这段代码在android中生成警告对话框。但是我想要左边的是按钮,右边没有按钮。我怎么能这样做?
public class App {
public static void main(String[] args) {
ThrdO to=new ThrdO();
Thread t1=new Thread(to);
ThredE te=new ThredE();
Thread t2=new Thread(te);
t1.start();
t2.start();
}
}
public class ThrdO implements Runnable{
PrintCl pcl =new PrintCl();
@Override
public void run() {
for(int i=0;i<10;i+=2)
pcl.Even(i);
}
}
public class ThredE implements Runnable {
PrintCl pcl =new PrintCl();
@Override
public void run() {
for(int i=1;i<10;i+=2)
try {
pcl.odd(i);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class PrintCl {
public void Even(int n) {
synchronized (this) {
System.out.println(n);
this.notifyAll();
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void odd(int n) throws InterruptedException {
synchronized (this) {
System.out.println(n);
this.notifyAll();
this.wait();
}
}
}
答案 0 :(得分:2)
您可以根据自己的意愿更改正面按钮中的文字,并在其中编写任何代码。
AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext());
builder.setCancelable(true);
builder.setTitle("Title");
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
builder.setNegativeButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
答案 1 :(得分:0)
这是我的解决方案。这对我有用。
def receive = runRoute(routes) orElse {
case CleanupFile(file) => Try(file.delete())
}