Google Maps自定义标记未加载Firebase图片

时间:2019-02-16 21:18:41

标签: java android firebase google-maps

我正在使用Java开发Android Studio应用。我的应用程序允许用户登录并使用自定义标记在地图上查看自定义标记。当用户点击自定义标记时,他们将进入另一项活动。

我的问题是,通过自定义标记访问此活动时,该应用程序不会加载存储在Firebase中的图像。

关于可能是什么问题的任何建议?谢谢。

map activity that deals with the markers:

mMap.setOnMarkerClickListener
(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if (marker.getTitle().equals("Mario's Italian"))
                startActivity(new Intent(MapView.this, 
                ItalianMenu.class));
            if (marker.getTitle().equals("Bamboo Tandoori"))
                startActivity(new Intent(MapView.this, 
                IndianMenu.class));
            if (marker.getTitle().equals("King Chinese 
            Takeaway"))
                startActivity(new Intent(MapView.this, 
                ChineseMenu.class));
            return false;
        }
    }); 



activity that opens up when a user clicks the marker:

package myapp.zerbu.partyloader;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;

import myapp.zerbu.partyloader.Common.Common;
import myapp.zerbu.partyloader.Interface.ItemClickListener;
import myapp.zerbu.partyloader.Model.Category;
import myapp.zerbu.partyloader.ViewHolder.MenuViewHolder;

public class ItalianMenu extends AppCompatActivity
    implements 
NavigationView.OnNavigationItemSelectedListener {


FirebaseDatabase database;
DatabaseReference category;

TextView txtName;

RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Mario's Italian");
    setSupportActionBar(toolbar);


    //Init Firebase
    database = FirebaseDatabase.getInstance();
    category = database.getReference("Category");

    //Basket
    FloatingActionButton fab = (FloatingActionButton)
 findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own 
action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) 
findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new
 ActionBarDrawerToggle(
            this, drawer, toolbar, 
R.string.navigation_drawer_open, 
R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) 
    findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


    //Set Name for user
    View headerView = navigationView.getHeaderView(0);
    txtName = 
    (TextView)headerView.findViewById(R.id.txtName);
    txtName.setText(Common.currentUser.getName());

    //Load menu
    recycler_menu = (RecyclerView) 
    findViewById(R.id.recycler_menu);
    recycler_menu.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(this);
    recycler_menu.setLayoutManager(layoutManager);

    loadMenu();
}

private void loadMenu() {

    FirebaseRecyclerAdapter<Category, MenuViewHolder> 
adapter = new FirebaseRecyclerAdapter<Category,
 MenuViewHolder>(Category.class, 
R.layout.activity_italian_menu, MenuViewHolder.class, 
category) {
        @Override
        protected void populateViewHolder(MenuViewHolder
 viewHolder, Category model, int position) {
            viewHolder.txtMenuName.setText(model.getName());

Picasso.with(getBaseContext()).load(model.getImage())
                    .into(viewHolder.imageView);
            final Category clickItem = model;

            viewHolder.setImageClickListener(new 
    ItemClickListener() {
                @Override
                public void onClick(View view, int position,
     boolean isLongClick) {
                    Toast.makeText(ItalianMenu.this, 
    ""+clickItem.getName(), Toast.LENGTH_SHORT).show();
                }
            });

        }
    };
    recycler_menu.setAdapter(adapter);
 }

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) 
    findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar 
if it is present.
    getMenuInflater().inflate(R.menu.home, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_restaurants) {
        // Handle the camera action
    } else if (id == R.id.nav_basket) {

    } else if (id == R.id.nav_orders) {

    } else if (id == R.id.nav_logout) {

    }

    DrawerLayout drawer = (DrawerLayout)
 findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
}

0 个答案:

没有答案