マップ上のマーカーをクリックすると、RecycleView内の位置に移動されます。 私はすでにマップ上にマーカーを持っていますが、それぞれマーカーはFirebaseから取り出され、MarkerOptionsのタイトルとして配置されています。 "alpha"タイトルが開いているブックマークをクリックし、RecycleViewの中にある "alpha"タイトルがある位置を表示するにはどうすればよいですか?マップ上のマーカーをクリックし、RecycleView内の位置を指示します
コードRecycleView:
public class ShowImagesActivity extends AppCompatActivity {
//recyclerview object
private RecyclerView recyclerView;
//adapter object
private RecyclerView.Adapter adapter;
//database reference
private DatabaseReference mDatabase;
//progress dialog
private ProgressDialog progressDialog;
//list to hold all the uploaded images
private List<Upload> uploads;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_images);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
progressDialog = new ProgressDialog(this);
uploads = new ArrayList<>();
//displaying progress dialog while fetching images
progressDialog.setMessage("Please wait...");
progressDialog.show();
mDatabase = FirebaseDatabase.getInstance().getReference(Constants.DATABASE_PATH_UPLOADS);
//adding an event listener to fetch values
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
//dismissing the progress dialog
progressDialog.dismiss();
//iterating through all the values in database
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Upload upload = postSnapshot.getValue(Upload.class);
uploads.add(upload);
}
//creating adapter
adapter = new MyAdapter(getApplicationContext(), uploads);
//adding adapter to recyclerview
recyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}
}
コードUpload.class:
public class Upload{
public String name;
public String description;
public String local;
public String url;
public String latitude;
public String longitude;
// Default constructor required for calls to
// DataSnapshot.getValue(User.class)
public Upload() {
}
public Upload(String name, String description,String local,String latitude, String longitude, String url) {
this.name = name;
this.description = description;
this.local = local;
this.url= url;
this.latitude = latitude;
this.longitude= longitude;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getLocal() {
return local;
}
public String getLongitude() {
return longitude;
}
public String getLatitude() {
return latitude;
}
public String getUrl() {
return url;
}
}
コードマップ:
ref.child("uploads").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterator<DataSnapshot> dataSnapshotsChat = dataSnapshot.getChildren().iterator();
while (dataSnapshotsChat.hasNext()) {
DataSnapshot dataSnapshotChild = dataSnapshotsChat.next();
String latitudeL = dataSnapshotChild.child("latitude").getValue().toString();
String longitudeL = dataSnapshotChild.child("longitude").getValue().toString();
double latitude1 = Double.parseDouble((latitudeL));
double longitude1 = Double.parseDouble(longitudeL);
LatLng local = new LatLng(latitude1, longitude1);
final String title = dataSnapshotChild.child("name").getValue().toString();
final String url = dataSnapshotChild.child("url").getValue().toString();
mMap.addMarker(new MarkerOptions().position(local).title(title));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(local, 10));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
//What I put here??
}}}
別のオプション? – FranciscoM