我在我的活动中加入了alertdialog
。
如果我点击Yes
,它应转移到下一个活动,如果我点击No
,它应移至另一个活动。
但是当我这样做时dialog
甚至没有出现。这是我的代码。有可能这样做吗?任何人都可以提供帮助。但是当我点击“否”时,我只调用finish()
,它正在工作。
以下是代码:
final Button submitCustomer = (Button) findViewById(R.id.submit_customer);
submitCustomer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
confirmRemoveOrder();
}
});
private void confirmRemoveOrder() {
new AlertDialog.Builder(this)
.setTitle("Confirm")
.setMessage("Are you sure you want to cancel this order ?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
deleteOrder();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
createCustomer();
}
});
}
}
答案 0 :(得分:2)
使用以下代码创建public static void main(String args[]) {
String s = ""; // Sample JSON to be parsed
JSONParser parser = new JSONParser();
JSONObject obj = null;
try {
obj = (JSONObject) parser.parse(s);
@SuppressWarnings("unchecked")
List<String> parameterKeys = new ArrayList<String>(obj.keySet());
List<String> result = null;
List<String> keys = new ArrayList<>();
for (String str : parameterKeys) {
keys.add(str);
result = this.addNestedKeys(obj, keys, str);
}
System.out.println(result.toString());
} catch (ParseException e) {
e.printStackTrace();
}
}
public static List<String> addNestedKeys(JSONObject obj, List<String> keys, String key) {
if (isNestedJsonAnArray(obj.get(key))) {
JSONArray array = (JSONArray) obj.get(key);
for (int i = 0; i < array.length(); i++) {
try {
JSONObject arrayObj = (JSONObject) array.get(i);
List<String> list = new ArrayList<>(arrayObj.keySet());
for (String s : list) {
putNestedKeysToList(keys, key, s);
addNestedKeys(arrayObj, keys, s);
}
} catch (JSONException e) {
LOG.error("", e);
}
}
} else if (isNestedJsonAnObject(obj.get(key))) {
JSONObject arrayObj = (JSONObject) obj.get(key);
List<String> nestedKeys = new ArrayList<>(arrayObj.keySet());
for (String s : nestedKeys) {
putNestedKeysToList(keys, key, s);
addNestedKeys(arrayObj, keys, s);
}
}
return keys;
}
private static void putNestedKeysToList(List<String> keys, String key, String s) {
if (!keys.contains(key + Constants.JSON_KEY_SPLITTER + s)) {
keys.add(key + Constants.JSON_KEY_SPLITTER + s);
}
}
private static boolean isNestedJsonAnObject(Object object) {
boolean bool = false;
if (object instanceof JSONObject) {
bool = true;
}
return bool;
}
private static boolean isNestedJsonAnArray(Object object) {
boolean bool = false;
if (object instanceof JSONArray) {
bool = true;
}
return bool;
}
:
您忘记添加:
<table>
<colgroup>
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
</colgroup>
<thead>
<tr>
<th>User Id</th>
<th>User Name</th>
<th>Date</th>
<th>Value</th>
</tr>
</thead>
<tr ng-repeat="obj in jsonArray">
<td align="middle">{{ obj.userId }}</td>
<td align="middle">{{ obj.username }}</td>
<td align="middle">{{ obj.date | date: 'yyyy-MM-dd' }}</td>
<td align="middle">{{ obj.value }}</td>
</tr>
</table>
创建对话框完整代码:
AlertDialog
在转到另一个活动之前,请不要忘记
AlertDialog alert = dialog.create(); alert.show();
对话框。
答案 1 :(得分:0)
您只是对ENUM(Admin,normal_user) UNIQUE
的 .show();
方法进行了操作,以显示您的AlertDialog.Builder()
如下所示进行更改
<强> CODE 强>
AlertDialog.Builder()
同时从
private void confirmRemoveOrder() { new AlertDialog.Builder(this) .setTitle("Confirm") .setMessage("Are you sure you want to cancel this order ?") .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { deleteOrder(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { createCustomer(); } }) .show(); }
中将ClickListener
中的一个submitCustomer
移除至已设置两次clickListener到submitCustomer
答案 2 :(得分:0)
要显示AlertDialog
,您需要执行更多步骤。
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("Confirm")
// add the rest of your setXYZ() methods here
.create(); // this will create your AlertDialog object.
alertDialog.show(); // and this displays it!
答案 3 :(得分:0)
您只需为alertDialog
添加.show()new AlertDialog.Builder(this)
.setTitle("Confirm")
.setMessage("Are you sure you want to cancel this order ?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
deleteOrder();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
createCustomer();
}
}).show();
只需添加它即可解决您的问题。