Android和Java初学者现在已经有2天的时间试图解决这个问题了。
我有
public class searchFromServer {
public List<String> lightHouses = new ArrayList<String>();
LightHouseList mLightHouseList = new LightHouseList();
List searchLightHouses(String find) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("userLocation");
query.whereEqualTo("username",find);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> searchedLightHouseList, ParseException e) {
if (e == null) {
for (int i = 0; i < searchedLightHouseList.size(); i++) {
mLightHouseList.addObjectToLightHousesList(searchedLightHouseList.get(i));
Log.d("parse", "searchedLightHouseList item #" + i + searchedLightHouseList.get(i).get("location"));
}
Log.d("parse", "Retrieved " + searchedLightHouseList.size() + " scores");
} else {
Log.d("parse", "Error: " + e.getMessage());
}
}
});
Log.d("test", String.valueOf(mLightHouseList.getLightHousesListSize()));
return lightHouses;
}
}
如果我理解正确,public void done方法正在创建ParseObjects列表,该列表名为&#34; searchingLightHouseList&#34;?
我如何从其他课程中访问此列表?
最近的尝试是使用Class并将其用作&#34;存储&#34;,但没有任何内容。至少
Log.d("test", String.valueOf(mLightHouseList.getLightHousesListSize()));
显示0。
import android.support.annotation.NonNull;
import android.widget.Toast;
import com.parse.ParseObject;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
/**
* Created by U36J on 11.9.2015.
*/
public class LightHouseList {
private List<ParseObject> LightHousesList = new List<ParseObject>() {
@Override
public void add(int location, ParseObject object) {
}
@Override
public boolean add(ParseObject object) {
return false;
}
@Override
public boolean addAll(int location, Collection<? extends ParseObject> collection) {
return false;
}
@Override
public boolean addAll(Collection<? extends ParseObject> collection) {
return false;
}
@Override
public void clear() {
}
@Override
public boolean contains(Object object) {
return false;
}
@Override
public boolean containsAll(Collection<?> collection) {
return false;
}
@Override
public ParseObject get(int location) {
return null;
}
@Override
public int indexOf(Object object) {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@NonNull
@Override
public Iterator<ParseObject> iterator() {
return null;
}
@Override
public int lastIndexOf(Object object) {
return 0;
}
@NonNull
@Override
public ListIterator<ParseObject> listIterator() {
return null;
}
@NonNull
@Override
public ListIterator<ParseObject> listIterator(int location) {
return null;
}
@Override
public ParseObject remove(int location) {
return null;
}
@Override
public boolean remove(Object object) {
return false;
}
@Override
public boolean removeAll(Collection<?> collection) {
return false;
}
@Override
public boolean retainAll(Collection<?> collection) {
return false;
}
@Override
public ParseObject set(int location, ParseObject object) {
return null;
}
@Override
public int size() {
return 0;
}
@NonNull
@Override
public List<ParseObject> subList(int start, int end) {
return null;
}
@NonNull
@Override
public Object[] toArray() {
return new Object[0];
}
@NonNull
@Override
public <T> T[] toArray(T[] array) {
return null;
}
};
public void addObjectToLightHousesList (ParseObject obj){
LightHousesList.add(obj);
}
public ParseObject getLightHousesListObject (int i){
return LightHousesList.get(i);
}
public int getLightHousesListSize () {return LightHousesList.size();
}
}