There are a few options for what you're trying to achieve. Personally, I'd recommend implementing your own Adapter (most likely in this case by extending SimpleCursorAdapter) and encapsulating the updates to distance text and compass heading rotation within that.
To help with resource management, you probably want to create a SensorListener and LocationListener within the Activity that will host the ListView. Whenever you receive an update call your self-rolled updateCompassAndLocation
method from within your Adapter class.
From within that method you have two options. Either iterate over each of the items that make up the data collection being represented and modify the compass graphic and distance text, or simply record the current location and heading as variables within the class, and call notifyDataSetChanged
to force the adapter to update the views itself within the getView
method. In either case (especially the latter), you'll need to set the distance text and heading compass values within getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout myView;
MyPOI item = getItem(position);
Location poiLocation = item.getLocation;
int compassHeading = // Calculate heading relative to current heading
float distance = // Calculate distance to POI
if (convertView == null) {
myView = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, myView, true);
} else {
trainView = (LinearLayout) convertView;
}
TextView distanceView = (TextView)trainView.findViewById(R.id.distance);
ImageView compassView = (InageView)trainView.findViewById(R.id.compass);
distanceView.setText(String.valueOf(distance);
compassView.setImageLevel(compassHeading);
}