gpt4 book ai didi

java - 将取消按钮添加到自定义警报对话框

转载 作者:行者123 更新时间:2023-12-02 00:39:09 24 4
gpt4 key购买 nike

我只是一个主题,而不是程序员,感谢任何帮助/指导。我正在尝试向此代码添加取消按钮:

public class gobuuf extends Activity {
/** Called when the activity is first created. */

class CustomAlertDialog extends AlertDialog {
public CustomAlertDialog(Context context) {
super(context);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean ret = super.onKeyDown(keyCode, event);
finish();
return ret;
}

public void setCancel(int buttonNegative, String string, Object object) {
// TODO Auto-generated method stub

}
}

private CustomAlertDialog mDialog;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

if (isExistSkin("com.gau.go.launcherex")) {
startGOLauncher("com.gau.go.launcherex");
finish();
return;
}

mDialog = new CustomAlertDialog(this);
mDialog.setTitle(R.string.dialogtitle);
mDialog.setMessage(getResources().getString(R.string.dialogcontent));
mDialog.setCancel(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.dialognothanks), null);
mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.dialogok),
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
String marketuriString = "market://search?q=pname:com.gau.go.launcherex";
Intent EMarketintent = new Intent(Intent.ACTION_VIEW, Uri.parse(marketuriString));
EMarketintent.setPackage("com.android.vending");
EMarketintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(marketuriString));
try {
startActivity(EMarketintent);
} catch (ActivityNotFoundException e) {
String link = "http://61.145.124.93/soft/3GHeart/com.gau.go.launcherex.apk";
Uri browserUri = Uri.parse(link);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, browserUri);
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(browserIntent);
} catch (ActivityNotFoundException e2) {
// TODO: handle exception
e2.printStackTrace();
}
} catch (Exception e3) {
// TODO: handle exception
e3.printStackTrace();
}
finish();

}
});
mDialog.show();
}


@Override
protected void onDestroy() {
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
}

private boolean isExistSkin(String packageName) {
try {
createPackageContext(packageName,
Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
return false;
}
return true;
}

private void startGOLauncher(String packageName){
PackageManager packageMgr = this.getPackageManager();
Intent launchIntent = packageMgr.getLaunchIntentForPackage(packageName);
if (null != launchIntent){
try
{
this.startActivity(launchIntent);
}
catch(ActivityNotFoundException e)
{

}
}
}
}

我已经添加了相应的字符串,但不知道还能做什么:添加一个 onclicklistener,我知道我需要某种在 finish() 某处编码的操作;或.取消某事。再次感谢您的帮助。

我应该说,我一直在玩弄你所看到的这一点:

mDialog.setCancel(DialogInterface.BUTTON_NEGATIVE,getResources().getString(R.string.dialognothanks), null);

最佳答案

我不确定这是否正是您正在寻找的内容,但您可以执行类似的操作...这只是关闭对话框。

.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}

对于创建对话框的非常好的教程,我建议使用:http://developer.android.com/guide/topics/ui/dialogs.html 。这应该非常有帮助。

关于java - 将取消按钮添加到自定义警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6854026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com