I have a recyclerView
with 5 cardView
. there are three Button in each cardview
.
One of this button invisible and when GPS data changed can be visible in only one cardview
.
my problem is I can't do this.
I try some way. one away is:
public void onLocationChanged(Location currentLocation) {
double latitude = currentLocation.getLatitude();
double longitude = currentLocation.getLongitude();
float[] results = new float[1];
for (int i = 1; i < list_count; i++) {
Location.distanceBetween(oldLat[i], oldLng[i],
latitude, longitude, results);
if (results[0] < 30) {
visible[i] = true;
} else {
visible[i] = false;
}
adapter.notifyItemChanged(i);
// adapter.notifyDataSetChanged();
}
}
and another way is:
public void onBindViewHolder(@NonNull final CustomAdapter.MyViewHolder holder, final int listPosition) {
final Button buttonPresent = holder.buttonPresent;
final Button buttonAbsent = holder.buttonAbsent;
final Button buttonGeo = holder.buttonGeo;
if (listPosition > -1) {
if (visible[listPosition]) {
buttonGeo.setVisibility(View.GONE);
} else {
buttonGeo.setVisibility(View.INVISIBLE);
}
}
adapter.notifyItemChanged(i);
// adapter.notifyDataSetChanged();
}
}
Default state for all buttonGeo in recyclerView is INVISIBLE. when one location reached,the button related to it must be VISIBLE for only one cardView. But I can't change button visibility and all button invisible. How do I solve this problem? Excuse me for my English.