繁体   English   中英

Android 自定义 ListView 未显示在 API 级别 28

[英]Android customized ListView not showing in API Level 28

在 Android 应用程序中,我有一个在警报对话框中显示的自定义ListView 它在Galaxy TAB A 7.0 API Level 22上完美运行。

我在Galaxy TAB A 8.0 API Level 28上运行了相同的应用程序。 AlertDialog未显示。

我怎样才能让它在两个设备上都工作?

我在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 工作正常。 我唯一需要知道的是AlertDialog没有显示在Android 9.0 API Level 28中的原因。

所以最后我得到了解决方案。 问题出在if condition 它应该是if(examResultCode.contains("2"))而不是if(examResultCode == "2")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM