Codigami / CFAlertDialog

MIT License
224 stars 47 forks source link

How to get ClickListener from costum header or footer with kotlin #23

Closed majid1605 closed 5 years ago

majid1605 commented 5 years ago

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 4.4
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually
Xcode Version e.g. Android Studio 3.2
depindersharma commented 5 years ago

I would also like to know the answer to this. I wanted to get text from Edittext which is added in custom view using builder.setFooterView(R.layout.some_footer_layout);

rahul-s commented 5 years ago

@majid1605 @pocketutilities Both of these can be achieved as follows

  1. Inflate the layout into a View object View customView = getLayoutInflater().inflate(R.layout.child, null);
  2. Set the OnClickListener, TextWatcher or any such listener to the appropriate view.
  3. Add this view as Header/Footer.

Let me know if you need any further help. You may also refer to the demo project in this repo.

majid1605 commented 5 years ago

why does the first code work and the second doesn't work?

customView.myBtnID.setOnClickListener {
                    Toast.makeText(this, "test", Toast.LENGTH_SHORT).show()
        }
customView.setOnClickListener {
        when(it.id)
{
R.id.myBtnID->
{
                    Toast.makeText(this, "test", Toast.LENGTH_SHORT).show()
}
}

and how dismiss dialog after click myBtn?or any object on my dialog?

depindersharma commented 5 years ago

Awesome that worked for me

rahul-s commented 5 years ago

@majid1605 You may keep a reference to the dialog using: CFAlertDialog alertDialog = builder.show(); And on click listeners of any view you can call dismiss on the alertDialog.