So im getting my data from a web service and using RecyclerView adapter.In RecyclerView.adapter's onBindviewholder method I want to pass the data to the recyclerView in the MainActivity but also pass the data (item) to MyMapsActivity.The thing is the onBindViewholder has setOnClickListener and setOnLongClickListener as controls that are being used. Is there either a way to send the data(item) using an intent that doesnt start the activity or is there a way I can wire up a new button within the onBindViewholder method because what happens is when the app starts up it goes straight to MyMapsActivity which is expected. Is there a way to control this by either using a new button that can interact with onBindViewholder or is there a way to pass the intent.putExtra without starting the MyMapsActivity.Maybe My understanding is flawed but here is my code for the methods and activities stated:
onBindViewholder
public void onBindViewHolder(DataItemAdapter.ViewHolder holder, int position) {
final DataItem item = mItems.get(position);
try {
holder.titletext.setText(item.getTitle());
holder.companyText.setText(item.getCompany());
holder.cityText.setText(item.getCity());
holder.salarytext.setText(""+ item.getSalary());
holder.descriptionText.setText(item.getDescription());
holder.responsibilityText.setText(item.getResponsibility());
holder.latText.setText(""+ item.getLatitude());
holder.lngText.setText(""+ item.getLongitude());
holder.phoneText.setText(item.getPhone());
holder.provinceText.setText(item.getProvince());
} catch (Exception e) {
e.printStackTrace();
}
//click
holder.mView.setOnClickListener(new View.OnClickListener() {//getting viewholder class and ctor
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext,DetailsActivity.class);
intent.putExtra(ITEM_KEY,item);
mContext.startActivity(intent);
}
});
//long click
holder.mView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(mContext, "long click: " + item.getTitle(), Toast.LENGTH_SHORT).show();
return false;
}
});
// !!!!!----this is the intent Im talking about----!!!
Intent intent = new Intent(mContext,MyMapActivity.class);
intent.putExtra(ITEM_KEY,item);
mContext.startActivity(intent);
}
My maps method :
public void onMapReady(GoogleMap googleMap) {
final DataItem item = getIntent().getExtras()
.getParcelable(DataItemAdapter.ITEM_KEY); //--------gets intent frm dataItemAdapter
if (item == null) {
throw new AssertionError("null data recived");
}
mapReady = true;
mMap = googleMap;
LatLng latLngToronto = new LatLng(43.733092, -79.264254);
// LatLng latLnghome = new LatLng(43.656729, -79.377162);
CameraPosition target = CameraPosition.builder().target(latLngToronto).zoom(15).tilt(65).build();
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(target));
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
markerDisplay(item.getTitle(),item.getLatitude(),item.getLongitude());//------maps jobs marker-------new
//add markers and
//instantiate
// mMap.addMarker(mp);
// mMap.addMarker(md);
}