0

我想从 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());

这是列表活动

  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);
    }
}
4

0 回答 0