gpt4 book ai didi

java - 检索类或对象的实例

转载 作者:行者123 更新时间:2023-12-01 09:18:11 24 4
gpt4 key购买 nike

我无法理解如何获取对象或类的某些实例。很抱歉提出新问题。我有一个名为 waypoint 的类,其中包含有关航点的一些基本信息,接下来我从服务器获取用户最喜欢的航点列表,然后检查服务器上最喜欢的航点列表是否与最喜欢的航点列表相匹配本地设备,如果不是,那么我需要使它们匹配,并且当尝试删除路径点的实例时,我不知道如何删除它的实际实例。我的代码如下:

waypoint.java

public class Waypoint
{
public long id;
public String name;
public Bitmap bitmap;
public boolean deleted;
public int waypoint_type;
public int waypoint_id;

public Waypoint(long id, String name, Bitmap bitmap, int waypoint_type, int waypoint_id)
{
this.id = id;
this.name = name;
this.bitmap = bitmap;
this.waypoint_type = waypoint_type;
this.waypoint_id = waypoint_id;
}
public long getId() {
return id;
}
}

MainActivity.java

public ArrayList<Waypoint> mWaypoint = new ArrayList<>();
mWaypoint .add(new Waypoint(getNewId(), name, BitmapFactory.decodeResource(getResources(), R.drawable.stoplogo_small), stopTypeInteger, idInteger));

//attempt to remove it from my live list view
int pos = mAdapterWaypoint.getPosition(WaypointObjectGoesHere); //I dont know how to get this instance that I need here.
mAdapterWaypoint.remove(WaypointObjectGoesHere); //I dont know how to get this instance that I need here.

最佳答案

迭代器可能是你的 friend :

    Iterator<Waypoint> iterator = mWaypoint.iterator();
Waypoint waypoint;
while (iterator.hasNext()) {
waypoint = iterator.next();
if (waypoint.getId() == 1) { // 1 is an example
iterator.remove();
}
}

关于java - 检索类或对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40369420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com