Search bar with ClickListener to the searched DetailActivity not working

Felix Saraiva :

I'm trying to open the respective DetailActivity that the user searches on a search bar that works with firebase real-time database, but I don't know how to pass the value on the click listener to that activity. I have this so far:

SearchAdapter.Java

    @Override
public void onBindViewHolder(@NonNull SearchViewHolder holder, int position) {

    holder.monName.setText(strPlaceList.get(position));
    holder.monLocation.setText(strLocationList.get(position));
    Glide.with(context).asBitmap().load(strImageList.get(position)).placeholder(R.mipmap.ic_launcher_round).into(holder.monumentImage);


    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (strPlaceList != null){
                Intent intent= new Intent(context,DetailActivity.class);
                intent.putExtra("placeName", "strPlaceList");
                context.startActivity(intent);
            }

        } });

}

DetailActivity.java

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    ButterKnife.bind(this);

    setupActionBar();

    Intent intent = getIntent();
    String placeName = intent.getStringExtra(EXTRA_DETAIL);

    DetailPresenter presenter = new DetailPresenter(this);
    presenter.getPlaceById(placeName);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    memoryCamera();

}

What else can I put on the Click listener so it opens the right activity that the user searched? Now it is only displaying the DetalAcitivity with no information on it.

UPDATED:

If it helps my app is trying to get this HTTP that is getting a null result.

https://project-4a153.firebaseio.com/Monuments/null.json (131ms)

DetailPresenter.java

public class DetailPresenter {
private DetailView view;

public DetailPresenter(DetailView view){ this.view = view; }

void getPlaceById(String placeName){

    view.showLoading();

    Utils.getApi().getPlacesByName(placeName+".json").enqueue(new Callback<Places>() {
        @Override
        public void onResponse(@NonNull Call<Places> call,@NonNull Response<Places> response) {
            view.hideLoading();
            if (response.isSuccessful() && response.body() !=null){
                view.setPlace(response.body().getPlaces().get(0));
            }else{
                view.onErrorLoading(response.message());
            }
        }

        @Override
        public void onFailure(@NonNull Call<Places> call,@NonNull Throwable t) {
            view.hideLoading();
            view.onErrorLoading(t.getLocalizedMessage());
        }
    });

  }
}
parques :

try adding the extra in the intent your creating in the SearchAdapter like this:

intent.putExtra(DetailActivity.EXTRA_DETAIL, strPlaceList.get(position));

the value key of the extra must be the same on both sides.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=284789&siteId=1