last day (23 days later) » 

07:38
1
A: notifyDataSetChanged() in Adapter doesn't seem to work

Nilesh RathodYou are not removing item from your list that's why notifyItemRemoved(position) and notifyDataSetChanged() is not working Make below changes in your code handler.postDelayed(Runnable { dialog.dismiss() // remove here item from yourlist then use notifyItem...

I need to use removeAt instead of remove
@JohnJoe didn't get u buddy
I get this Using 'remove(Int): T' is an error. Use removeAt(index) instead
@JohnJoe ok did it works?
yes,thanks a lot
hi bro, I have another button called A in the recyclerView. If A clicked, it will call some function, then I want A to be invisible. How can I achieve ?
07:38
@JohnJoe than you need to take a boolean variable for that and maintain boolean visibilty of button called A using that boolean varble, means when user click on button change the state of boolean variable and disply button based on that Boolean variable
@JohnJoe for hint check my previous answer stackoverflow.com/a/54103578/7666442
hello there
I don't really get your answer
The button A is one of the recyclerView item
First take a boolean varble in your class
not adapter class right ?
07:41
if boolean == true display your button A else make invisible
in your model or pojo class
when user click on button A make boolean varble false and use notifyDataSetChanged()
my POJO class
var selected:Boolean = false
override fun onBindViewHolder(holder: ViewHolder, position: Int) {

val item = mValues[position]

if(mValues.get(position).selected){

}else{

}
adapter class
if(mValues.get(position).selected){
/// display button A
}else{
/// make button A visibilty gone
}
and this is A button onClickListener in adapter class
holder.mAppButton.setOnClickListener {
var dialog = Util().callDialog(context)
// do somethig
// then hide the button
}
07:48
holder.mAppButton.setOnClickListener {
var dialog = Util().callDialog(context)
mValues.get(position).selected=false
notifyDataSetChanged()
}
I think is mValues.get(position).selected=true
its `mValues.get(position).selected=false` because we have used below condition

f(mValues.get(position).selected){
/// if true display button A
}else{
/// if false make hide the button button A visibilty gone
}
but you can change the logic as per your requirement
wait ya
strange
when it come to OnBindView
if (mValues.get(position).selected) {
context.longToast(mValues.get(position).selected.toString())
holder.mAppButton.visibility = View.VISIBLE
} else {
context.longToast("SSS "+mValues.get(position).selected.toString())
holder.mAppButton.visibility = View.GONE
}
it will display SSS false
and all A button not visible
08:18
share your adpter code
@JohnJoe make sure when u set adapter your selected is true
for all item
override fun onBindViewHolder(holder: ViewHolder, position: Int) {

val item = mValues[position]

if (item.work_order.equals(null) || (item.work_order?.equals(0)!!)) {
if (!item.status.equals("Complete")) {
holder.mAppButton.visibility = View.VISIBLE
mValues.get(position).selected = true
} else {
holder.mAppButton.visibility = View.GONE
mValues.get(position).selected = false
}
} else {
holder.mAppButton.visibility = View.GONE
mValues.get(position).selected = false
}

if (mValues.get(position).selected ==true) {
Initially there are 3 list in listView
the first one has mAppButton, but the other two dont have
where you are adiing data in your list
adding*
fun getListFromServer() {

GlobalScope.launch(Dispatchers.Main) {
swipe_container?.isRefreshing = true

val response = WebApi.getWorkRequests(context)

if (response?.status ==101) {
response.work_requests?.sortByDescending {
it.created_at
}

if (list != null) {
list.adapter = WorkRequestsRecyclerViewAdapter(
context!!,
response.work_requests!!,
this@WorkRequestsFragment
)
}
}
swipe_container?.isRefreshing = false
}
}
08:28
simple reverse the condition my friend
if(!mValues.get(position).selected){
/// display button A
}else{
/// make button A visibilty gone
}
holder.mAppButton.setOnClickListener {
var dialog = Util().callDialog(context)
mValues.get(position).selected=true
notifyDataSetChanged()
}
now try
how about in pojo class
var selected:Boolean = true
i don't why don't u check that
all 3 buttons become visible
is it because of this ?

if (item.work_order.equals(null) || (item.work_order?.equals(0)!!)) {
if (!item.status.equals("Complete")) {
holder.mAppButton.visibility = View.VISIBLE
mValues.get(position).selected = true
} else {
holder.mAppButton.visibility = View.GONE
mValues.get(position).selected = false
}
} else {
holder.mAppButton.visibility = View.GONE
mValues.get(position).selected = false
}
may be because i don't know why you have added that conditions
let me try
the three buttons still visible
solved
but the recyclerView not going to refresh
update *

  last day (23 days later) »