0

In Android application I have a custom ListView that I am displaying in Alert dialog. It works perfectly on Galaxy TAB A 7.0 API Level 22.

I have run the same application on Galaxy TAB A 8.0 API Level 28. The AlertDialog is not showing.

How can i make it work on both devices?

Code I am using in 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();
}

Rest is working fine. Only thing i need to know is the reason of AlertDialog not showing in Android 9.0 API Level 28.

Boken
  • 4,825
  • 10
  • 32
  • 42
  • can you post the logcat error you got on the other device? – Zain Apr 19 '20 at 19:51
  • Can you include your AlertDialog import statement? There are two different types and that might make a difference – Jahnold Apr 19 '20 at 19:51
  • @Zain there is no error in logcat. i am running a service to fetch data and show it in alert dialog. following is the response from server. errorMessage:The Operation/Result Return Successfully. – شبير البلوشي Apr 19 '20 at 19:58

1 Answers1

0

so finally i got the solution. the problem was in if condition. it supposed to be if(examResultCode.contains("2")) instead if(examResultCode == "2").