Noby
Noby

Reputation: 6602

How to set listener on custom dialog...?

I have a custom dialog view having a list view in its content.

I have set a onItemClickListener on the list but its not working...

Can anyone have any idea on this, please help.

here is my code.

dialog = new Dialog(context);
            customDialogAdapter = new CustomDialogListAdapter(context,PaymentInfo.creditCardTypes);
            dialog.setContentView(R.layout.custom_dialog);
            list = (ListView) dialog.findViewById(R.id.custom_list);
            list.setAdapter(customDialogAdapter);           

            // Recognizing custom layout parameters.
            list.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                        long arg3) {
                    System.out.println("Clicked on list...!");
                    tv = (TextView) arg1.findViewById(R.id.text);
                    radio = (RadioButton) arg1.findViewById(R.id.radio);
                    radio.setChecked(true);
                    System.out.println("You Clicked on "+tv.getText().toString());
                    dialog.dismiss();               
                }
            });

shap shot.

enter image description here

Thanks in advance...!

Upvotes: 1

Views: 2317

Answers (2)

Noby
Noby

Reputation: 6602

I found a solution to my problem..

That i am setting a listener in adapter which is giving me the list view.

Now its Working. :)

Upvotes: 1

Randy Martinez
Randy Martinez

Reputation: 133

sorry for not answering or giving a solution to your problem. But I have a suggestion, why don't you create an Activity (or ListActivity) with Dialog theme? That way you can have all the flexibilities of an Activity and not be constrained with creating a list in a Dialog.

Upvotes: 1

Related Questions