3
android.I에서 listview의 위도와 경도 목록을 5 초마다 표시하려고합니다.이 항목을 시도했습니다.android의 listview에서 위도와 경도 목록을 모두 표시
내 Main 클래스은 다음과 같습니다 -
public class MapdemoActivity extends ListActivity
{
private ArrayList<MapData> mapdata = new ArrayList<MapData>();
private MapDataAdapter m_adapter;
public String lng;
public String lat;
private Button retrieveLocationButton;
private LocationManager locationManager;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; //1 meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 5000; //5 seconds
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
this.m_adapter = new MapDataAdapter(this, R.layout.row, mapdata);
setListAdapter(this.m_adapter);
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location)
{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null)
{
lat=Double.toString(location.getLatitude());
lng=Double.toString(location.getLongitude());
MapData data = new MapData();
data.setLatitude(lat);
data.setLongitude(lng);
mapdata.add(data);
Log.i("Lat", mapdata.get(0).Latitude);
Log.i("Lng", lng+location.getLatitude());
}
}
public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(MapdemoActivity.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(MapdemoActivity.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(MapdemoActivity.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
private class MapDataAdapter extends ArrayAdapter<MapData>
{
private ArrayList<MapData> items;
public MapDataAdapter(Context context, int textViewResourceId, ArrayList<MapData> items)
{
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
MapData o = items.get(position);
if (o != null)
{
TextView lat = (TextView) v.findViewById(R.id.tt1);
TextView lng = (TextView) v.findViewById(R.id.tt2);
if (lat != null)
{
lat.setText("Latitude: "+o.getLatitude());
}
if(lng != null)
{
lng.setText("Longitude: "+ o.getLongitude());
}
}
return v;
}
}
}
MapData 클래스
package com.ap.map.demo;
public class MapData
{
public String Longitude;
public String Latitude;
public String getLatitude() {
return Latitude;
}
public void setLatitude(String latitude) {
this.Latitude = latitude;
}
public String getLongitude() {
return Longitude;
}
public void setLongitude(String longitude) {
this.Longitude = longitude;
}
}
그것은 변화를 인식지고 있지 않은 listview.No error.But에서 아무것도 표시되지 않습니다. 누구든지이 일을 도울 수 있습니까?