override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_event)
activity = this@CreateEventActivity
var clicable = true
val set_data : ArrayList<Category_Spinner_model> = ArrayList<Category_Spinner_model>()
if(clicable) dropdown_lay.setOnClickListener{
category_recycler.layoutManager = LinearLayoutManager(this)
set_data.add(Category_Spinner_model(R.drawable.ic_facebook,"Entertainment",R.drawable.ic_dropdown_arrow))
set_data.add(Category_Spinner_model(R.drawable.ic__entertainment,"Entertainment",R.drawable.ic_dropdown_arrow))
set_data.add(Category_Spinner_model(R.drawable.ic__entertainment,"Entertainment",R.drawable.ic_dropdown_arrow))
val adapter = Category_recycler_view(set_data)
category_recycler.adapter = adapter
clicable = false
Log.e("clicable->","$clicable")
}
else if(!clicable) dropdown_lay.setOnClickListener{
set_data.clear()
val adapter = Category_recycler_view(set_data)
category_recycler.adapter = adapter
clicable = true
}
}
I have a recycler view and set data to that recycler view via adapter i need to show the recycler view when clicked and remove the recycler on other click
CodePudding user response:
Your condition is out of place.
if(clicable) dropdown_lay.setOnClickListener{
...
}
Put it inside the onClickListener
like this instead.
dropdown_lay.setOnClickListener{
if (clicable) {
category_recycler.layoutManager = LinearLayoutManager(this)
...
...
clicable = false
} else {
set_data.clear()
...
...
clicable = true
}
}