如何使用群集中的项目Google Maps Utils显示ListView

时间:2016-05-27 02:00:29

标签: android android-maps-v2 android-maps-utils

我想添加来自Clusters和onClusterClick的项目我想在ListView中显示它们。如何将这些项添加到listView中,并在同一个Activity中的覆盖列表视图中显示。

@Override
    public boolean onClusterClick(Cluster<MapPosts> cluster) {
        // Show a toast with some info when the cluster is clicked.
        maparraylist = new ArrayList<>(cluster.getSize());
        try {
            for (MapPosts posts : cluster.getItems()) {
                String firstName = posts.name;
                String thumbNail = posts.profilePhoto;
                MapModel map = new MapModel();
                map.setName(firstName);
                map.setThumbs(thumbNail);
                maparraylist.add(map);
                Toast.makeText(CustomClustering.this,String.valueOf(maparraylist.size()),Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e){
            e.printStackTrace();
        } 
       Intent intent = new Intent(ClusteringActivity.this, MapsListActivity.class)
    }

这是我用来加载到GridView的适配器类

Context context;
    LayoutInflater inflater;
    private List<MapModel> maparraylist = null;
    private ArrayList<MapModel> arraylist;

    public MapsListAdapter(Context context, List<MapModel> maparraylist) {
        this.context = context;
        this.maparraylist = maparraylist;
        inflater = LayoutInflater.from(context);
        this.arraylist = new ArrayList<MapModel>();
        this.arraylist.addAll(maparraylist);
    }

    public class ViewHolder {
        ImageView thumbs;
        TextView name;
    }

    @Override
    public int getCount() {
        return maparraylist.size();
    }

    @Override
    public Object getItem(int position) {
        return maparraylist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public View getView(final int position, View view, ViewGroup parent) {
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.feeds_layout, null);
            // Locate the ImageView in gridview_item.xml
            holder.thumbs = (ImageView) view.findViewById(R.id.videoThumb);
            holder.name = (TextView) view.findViewById(R.id.grid_item_title);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        // Load image into GridView
        Picasso.with(context)
                .load(maparraylist.get(position).getThumbs())
                .transform(new CircleTransform())
                .resize(200,200)
                .centerCrop()
                .into(holder.thumbs);
        holder.name.setText(maparraylist.get(position).getName());

这是ListActivity

  GridView gridview;
    MapsListAdapter adapter;
    private List<MapModel> maparraylist = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from gridview_main.xml
        setContentView(R.layout.feeds_layout);
        // Execute RemoteDataTask AsyncTask
        gridview = (GridView) findViewById(R.id.gridview);
        // Pass the results into ListViewAdapter.java
        adapter = new MapsListAdapter(MapsListView.this,
                maparraylist);
        // Binds the Adapter to the ListView
        gridview.setAdapter(adapter);
    }
}

0 个答案:

没有答案