【发布时间】:2020-04-19 19:42:46
【问题描述】:
在 Android 应用程序中,我有一个自定义 ListView,我在警报对话框中显示。它在Galaxy TAB A 7.0 API Level 22 上完美运行。
我在Galaxy TAB A 8.0 API Level 28 上运行了相同的应用程序。 AlertDialog 未显示。
我怎样才能让它在两个设备上都工作?
我在onPostExecute() mmethod 中使用的代码:
if (examResultCode == "2") {
JSONArray jsonArray1 = jsonObj.getJSONArray("fail-type-Items");
for (int i = 0; i < jsonArray1.length(); i++) {
JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
String failTypeItemCode = jsonObject1.getString("fail-type-item-code");
String failTypeItemArName = jsonObject1.getString("fail-type-item-ar-name");
String failTypeItemEnName = jsonObject1.getString("fail-type-item-en-name");
ApplicantFailTypeItemDTO ApplicantFailTypeItemDTO = new ApplicantFailTypeItemDTO(failTypeItemCode, failTypeItemArName, failTypeItemEnName);
applicantFailTypeItem.add(ApplicantFailTypeItemDTO);
}
if (jsonArray1 != null && jsonArray1.length() > 0) {
FailTypeCustomAdapter failTypeCustomAdapter = new FailTypeCustomAdapter(MyActivity.this, applicantFailTypeItem);
View convertView = (View) getLayoutInflater().inflate(R.layout.applicant_failtype_custom_listview, null);
failTypeListView = (ListView) convertView.findViewById(R.id.failTypeCustomListView);
failTypeListView.setAdapter(failTypeCustomAdapter);
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyActivity.this);
alertDialog.setCancelable(false)
.setTitle(getResources().getString(R.string.title);
final AlertDialog alert = alertDialog.create();
// add custom view in dialog
alert.setView(convertView);
alert.setButton(Dialog.BUTTON_NEUTRAL, getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
alert.dismiss();
// mMyTask.cancel(true);
}
});
// show dialog
alert.show();
}
} else {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MyActivity.this);
// mBuilder.setTitle(R.string.Error);
mBuilder.setMessage(errorCode + " " + errorMessage)
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new CheckList().execute();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
"No Clicks", Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = mBuilder.create();
alert.show();
}
休息工作正常。我唯一需要知道的是AlertDialog 没有显示在Android 9.0 API Level 28 中的原因。
【问题讨论】:
-
你能把你在另一台设备上遇到的 logcat 错误贴出来吗?
-
您能否包含您的 AlertDialog 导入语句?有两种不同的类型,可能会有所不同
-
@Zain logcat 没有错误。我正在运行一项服务来获取数据并将其显示在警报对话框中。以下是来自服务器的响应。 errorMessage:操作/结果返回成功。