0

If the showChatList() function is not being called in the code, and the dialog is displayed normally.

When the listView is called via showChatList() function, it does not work.

To the original custom dialog

Is it impossible to bring up the listView?

public void callFunction() {

    final Dialog dlg = new Dialog(context);

    dlg.setContentView(R.layout.room_list);

    dlg.show();

    final Button okButton = (Button) dlg.findViewById(R.id.okButton);
    final Button backbtn = (Button) dlg.findViewById(R.id.backbtn);

    **final ListView chat_list = (ListView) dlg.findViewById(R.di.chat_list);**

    - or

    **chat_list = dlg.findViewById(R.id.chat_list);**

    backbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dlg.dismiss();
        }
    });

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dlg.dismiss();
        }
    });

    showChatList();
}

enter image description here

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
LEE
  • 33
  • 1
  • 8
  • Would you mind to describe better your intent in the code, with the info provided is hard to provide a proper answer – JPRLCol Sep 21 '20 at 15:27
  • If the `ListView` is indeed in the `Dialog`'s `room_list` layout, then you need to find `chat_list` the same way you are the two `Button`s in `callFunction()`, from the `Dialog`; e.g., `chat_list = dlg.findViewById(R.id.chat_list_or_whatever_the_id_is)`. – Mike M. Sep 21 '20 at 21:55
  • @MikeM. thx for the answer. I trying to your suggest code, but I got same problem. – LEE Sep 22 '20 at 02:52
  • We'd need to see your updated code. Please [edit] your question to update with what you have now. – Mike M. Sep 22 '20 at 02:53
  • @MikeM. I tried using the code you suggested to two examples, but it didn't work. – LEE Sep 22 '20 at 04:01
  • How exactly is it not working? That wasn't really clear in the original question either. Is it crashing? Is the `ListView` just not showing in the `Dialog`? Something else? – Mike M. Sep 22 '20 at 04:18
  • @MikeM. The app is stopped when the Dialog is called up. If I don't use showChatList() function, it works normally. – LEE Sep 22 '20 at 04:30
  • Oh, OK. I read your question as meaning that the `ListView` just wasn't visible in the `Dialog`. If it's crashing, there will be a stack trace in your logcat that will point out the exact cause. Have a look at [this answer](https://stackoverflow.com/a/23353174) to see where you can find that stack trace, and what it will look like. Please add the whole thing to your question, as text, when you find it. – Mike M. Sep 22 '20 at 04:33
  • @MikeM. I Added image link on post. – LEE Sep 22 '20 at 04:43
  • OK, you didn't mention that you're calling this code from another `Activity`. The problem is that your `RoomList` class should not extend `AppCompatActivity`, as it is not being used as an `Activity`. It's just a helper class. If you really want to keep all of this stuff in that separate class, then you need remove the `extends AppCompatActivity` from the class declaration, and use your `private Context context;` field for anything that requires a `Context`; e.g., `new ArrayAdapter(context, ...)`. (Btw, please post all text as text, rather than as screenshots.) – Mike M. Sep 22 '20 at 04:53
  • @MikeM. OMG!! Thank you so much for your hard work for me. Now it works really fine :D – LEE Sep 22 '20 at 05:19
  • No problem. In the future, please provide a little more detail in your questions – e.g., describe exactly how it's not working, how the given code is called, etc. – and if it's crashing, please post the stack trace at the start. It'll make it much easier for us to get you a solution. Anyhoo, glad you got it working. Cheers!. – Mike M. Sep 22 '20 at 05:23

2 Answers2

0

Your adapter depends on firebase. It will wait until it gets data, then I believe you need to call

    adapter.notifyDataSetChanged();

after

    adapter.add();
Abdullah Z Khan
  • 1,272
  • 1
  • 8
  • 18
0

When dealing with views like dialogs, it is important to load all the views needed in the dialog before calling dialog.show(). Alternatively, I'll suggest the use of DialogFragment with this example: https://blog.mindorks.com/implementing-dialog-fragment-in-android. DialogFragments allow you to manage your dialogs just like any other fragment.

Let me know which one you're able to use.

Jeff
  • 151
  • 2
  • 8