[英]Android customized ListView not showing in API Level 28
In Android application I have a custom ListView
that I am displaying in Alert dialog.在 Android 应用程序中,我有一个在警报对话框中显示的自定义ListView
。 It works perfectly on Galaxy TAB A 7.0 API Level 22
.它在Galaxy TAB A 7.0 API Level 22
上完美运行。
I have run the same application on Galaxy TAB A 8.0 API Level 28
.我在Galaxy TAB A 8.0 API Level 28
上运行了相同的应用程序。 The AlertDialog
is not showing. AlertDialog
未显示。
How can i make it work on both devices?我怎样才能让它在两个设备上都工作?
Code I am using in onPostExecute()
mmethod:我在onPostExecute()
方法中使用的代码:
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();
}
Rest is working fine. Rest 工作正常。 Only thing i need to know is the reason of AlertDialog
not showing in Android 9.0 API Level 28
.我唯一需要知道的是AlertDialog
没有显示在Android 9.0 API Level 28
中的原因。
so finally i got the solution.所以最后我得到了解决方案。 the problem was in if condition
.问题出在if condition
。 it supposed to be if(examResultCode.contains("2"))
instead if(examResultCode == "2")
.它应该是if(examResultCode.contains("2"))
而不是if(examResultCode == "2")
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.