The main problem is that recyclerview
is not clickable. But I might use the wrong way to delete "!" when intent to the next pages, which is map. If I do this way the map only shows one user marker, but it is supposed to show two markers.
In ListOnline.java
private void updateList() {
adapter = new FirebaseRecyclerAdapter<User, ListOnlineViewHolder>(
User.class,
R.layout.user_layout,
ListOnlineViewHolder.class,
counterRef
){
@Override
protected void populateViewHolder(ListOnlineViewHolder viewHolder, final User model, int position) {
viewHolder.txtEmail.setText(model.getEmail());
// item click recycler view
viewHolder.itemClickListenener = new ItemClickListenener() {
@Override
public void onClick(View view, int position) {
//if model is current user , not set click event
if(!model.getEmail().equals(FirebaseAuth.getInstance().getCurrentUser().getEmail()))
{
Intent map = new Intent(ListOnline.this, MapTracking.class);
map.putExtra("email",FirebaseAuth.getInstance().getCurrentUser().getEmail());
map.putExtra("lat",mLastLocation.getLatitude());
map.putExtra("lng",mLastLocation.getLongitude());
startActivity(map);
}
}
};
}
};
adapter.notifyDataSetChanged();
listOnline.setAdapter(adapter);
}
After I change like this , i can be clickable but cant receive the friend marker.
if(model.getEmail().equals(FirebaseAuth.getInstance().getCurrentUser().getEmail()))
means, i delete the '!' it can be intent to google map.
In ListOnlineViewHolder.java
public class ListOnlineViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView txtEmail;
ItemClickListenener itemClickListenener;
public ListOnlineViewHolder(View itemView) {
super(itemView);
txtEmail = (TextView)itemView.findViewById(R.id.txt_email);
itemView.setOnClickListener(this);
}
public void setItemClickListenener(ItemClickListenener itemClickListenener){
this.itemClickListenener = itemClickListenener;
}
@Override
public void onClick(View view) {
itemClickListenener.onClick(view,getAdapterPosition());
}}
In ItemClickListenener Interface
public interface ItemClickListenener {
void onClick(View view, int position);
}
In MapTracking
private void loadLocationForThisUser(String email) {
Query user_location = locations.orderByChild("email").equalTo(email);
user_location.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapShot:dataSnapshot.getChildren())
{
Tracking tracking = postSnapShot.getValue(Tracking.class);
//add marker for friend location
LatLng friendLocation = new LatLng(Double.parseDouble(tracking.getLat()),
Double.parseDouble(tracking.getLng()));
//create location from user coordinates
Location currentUser = new Location("");
currentUser.setLatitude(lat);
currentUser.setLongitude(lng);
//create location from friend coordinates
Location friend = new Location("");
friend.setLatitude(Double.parseDouble(tracking.getLat()));
friend.setLongitude(Double.parseDouble(tracking.getLng()));
//create function calculate distance between location
// distance(currentUser,friend);
//add friend marker on map
mMap.addMarker(new MarkerOptions()
.position(friendLocation)
.title(tracking.getEmail())
.snippet("Distance "+new DecimalFormat("#.#").format( distance(currentUser,friend)))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat,lng),12.0f));
}
//create marker for current user
LatLng current = new LatLng(lat,lng);
mMap.addMarker(new MarkerOptions().position(current).title(FirebaseAuth.getInstance().getCurrentUser().getEmail()));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Please help me, I spent almost a month to solve this project problem.
Pro, please, help me to see what is the problem, because I'm new to android. I'm most doing in Website server, PHP JAVAscript, HTML..
通过删除解决
if(!model.getEmail().equals(FirebaseAuth.getInstance().getCurrentUser().getEmail()))``
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.