X, Y는 현재의 위도, 경도인데,
장치에서 받아오는 속도가 느려
처음에는 0,0이며, 몇 초후에 X,Y값이 제대로 받아집니다.
그래서
notifyDataSetChanged() 를 사용하여
데이터가 바뀔때(X, Y값이 제대로 들어왔을 때)
새로 거리를 계산한 값이 출력되도게 하고자 합니다.
그런데, 아래와 같이 하니 빈 리스트만 출력이됩니다.
도움 부탁드립니다.
ArrayList<HashMap<String, Object>> originalValues;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ListView insurListView = (ListView) findViewById(android.R.id.list);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String names[] = {
"Tom",
"Jane",
"Mary",
};
Double lati[] = {
35.000001,
26.000001,
67.000001,
};
Double longi[] = {
129.000001,
159.000001,
100.000001,
};
originalValues = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> temp;
if (x==0){
originalValues.clear();
}
else{
int oriname = names.length;
for (int i = 0; i < oriname; i++) {
temp = new HashMap<String, Object>();
temp.put("name", names[i]);
temp.put("lati", lati[i]);
temp.put("longi", longi[i]);
temp.put("dis", Math.round(Math.round(6371000.0 * Math.acos(Math.sin(Math.PI/180 * lati[i]) * Math.sin(Math.PI/180 * Double.valueOf(x))
+ Math.cos(Math.PI/180 * lati[i]) * Math.cos(Math.PI/180 * Double.valueOf(x)) * Math.cos(Math.PI/180 * (longi[i] - Double.valueOf(y)
)))) / 1000));
originalValues.add(temp);
}
adapter.notifyDataSetChanged();
}
adapter = new CustomAdapter(this,R.layout.tab01_consul_row, originalValues);
insurListView.setAdapter(adapter);