当我使用
时protected void onPostExecute(String result) {
if (result.contentEquals("Success")) {
if(tellAFriend.message.contentEquals("Success")){
showAlert(TellAFriend.this, getResources().getString(R.string.tell_friend_alert), "1");
//After showing alertbox clicking ok it has to go to myclass instead of homescreen
} else if(tellAFriend.message.contentEquals("Failure")){
if ((language.contentEquals("")) || (language.contentEquals("en"))) {
showAlert(TellAFriend.this, Contact.Reason_Eng,"3");
} else if(language.contentEquals("ar")){
showAlert(TellAFriend.this, Contact.Reason_Ar,"3");
}
}
} else {
showAlert(TellAFriend.this, "Response Failure", "1");
}
Dialog.dismiss();
}
public void showAlert(final Context context, String message,
final String type) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder
.setTitle(getResources().getString(R.string.app_name));
language = sharedPreference.getString("language", "");
if ((language.contentEquals("")) || (language.contentEquals("en"))) {
alertDialogBuilder
.setMessage(message)
.setCancelable(false)
.setNeutralButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
if (type.contentEquals("1")) {
finish();
Intent mainwin = new Intent(context,
MainWindow.class);
startActivity(mainwin);
} else if (type.contentEquals("2")) {
finish();
Intent intentList = new Intent(context,
OilTrackerListView.class);
startActivity(intentList);
} else if (type.contentEquals("3")) {
dialog.dismiss();
}
dialog.dismiss();
}
});
} else if (language.contains("ar")) {
alertDialogBuilder
.setMessage(message)
.setCancelable(false)
.setNeutralButton(getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
if (type.contentEquals("1")) {
finish();
Intent mainwin = new Intent(context,
MainWindow.class);
startActivity(mainwin);
} else if (type.contentEquals("2")) {
finish();
Intent intentList = new Intent(context,
OilTrackerListView.class);
startActivity(intentList);
} else if (type.contentEquals("3")) {
dialog.dismiss();
}
dialog.dismiss();
}
});
}
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
警报框打开,当我点击确定时屏幕进入主屏幕。我需要打开另一个类而不是homescreen.i无法找到showalert.Just现在发现。我认为这是一个已定义的功能在android。
答案 0 :(得分:0)
AlertDialog中的OK按钮的监听器必须是这样的。我认为您正在呼叫finish() in onClick()
alert.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alert.dismiss();
}
});
答案 1 :(得分:0)
我想我必须在这里改变
if (type.contentEquals("1")) {
finish();
Intent mainwin = new Intent(context,
whichclassiwant.class);
startActivity(mainwin);
}