I am making an application that use skyhoo technology. I am pretty new to java and apparently I am making a mistake: I am modifying a UI object in a non-UI thread at:
printLocation(location.getLatitude(), location.getLongitude());
I heard I should use a handler and did look at that but wonder if there is a simpler way ? I have no clue how to implement a handler... Second I dont know what is should use in private done()
package nl.freshsolutions.kmregistratie;
import java.text.DateFormat;
import java.util.Date;
import com.skyhookwireless.wps.WPS;
import com.skyhookwireless.wps.WPSAuthentication;
import com.skyhookwireless.wps.WPSContinuation;
import com.skyhookwireless.wps.WPSLocation;
import com.skyhookwireless.wps.WPSLocationCallback;
import com.skyhookwireless.wps.WPSReturnCode;
import com.skyhookwireless.wps.WPSStreetAddressLookup;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.content.Context;
import android.content.Intent;
public class aanmaaknieuw extends Activity {
private EditText mystart;
private EditText myend;
private EditText mydistance;
private EditText mydiscription;
private EditText mydate;
private Long mRowId;
private NotesDbAdapter mDbHelper;
private static final int ACTIVITY_OVERZICHT=1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
setContentView(R.layout.aanmaaknieuw);
mystart = (EditText) findViewById(R.id.start);
myend = (EditText) findViewById(R.id.end);
mydistance = (EditText) findViewById(R.id.distance);
mydiscription = (EditText) findViewById(R.id.discription);
mydate = (EditText) findViewById(R.id.date);
Date now = new Date();
DateFormat df = DateFormat.getDateInstance();
String s = df.format(now);
mydate.setText(s);
Button safe = (Button) findViewById(R.id.safe);
safe.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String start = mystart.getText().toString();
String end = myend.getText().toString();
String distance = mydistance.getText().toString();
String discription = mydiscription.getText().toString();
String date = mydate.getText().toString();
if (mRowId == null) {
long id = mDbHelper.createNote(start, end, distance, discription, date);
if (id > 0) {
mRowId = id;
okaytextvullen();
}
} else {
//do some errorhandling of een andere actie
}
}
});
Button getlocation = (Button) findViewById(R.id.getlocation);
getlocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Context myAndroidContext = view.getContext();
// Create the authentication object
// myAndroidContext must be a Context instance
WPS wps = new WPS(myAndroidContext);
WPSAuthentication auth = new WPSAuthentication("andykalbvleesch", "freshsolutions.nl");
// Callback object
WPSLocationCallback callback = new WPSLocationCallback()
{
// What the application should do after it's done
public void done()
{
// after done() returns, you can make more WPS calls.
}
// What the application should do if an error occurs
public WPSContinuation handleError(WPSReturnCode error)
{
//handleWPSError(error); // you'll implement handleWPSError()
// To retry the location call on error use WPS_CONTINUE,
// otherwise return WPS_STOP
return WPSContinuation.WPS_STOP;
}
// Implements the actions using the location object
public void handleWPSLocation(WPSLocation location)
{
printLocation(location.getLatitude(), location.getLongitude());
}
};
// Call the location function with callback
wps.getLocation(auth, WPSStreetAddressLookup.WPS_NO_STREET_ADDRESS_LOOKUP,
callback);
}});
}
private void printLocation(double latitude, double longitude) {
String strlat = Double.toString(longitude)+ " - " + Double.toString(latitude);
mystart.setText("Location:" + strlat);
}
private void okaytextvullen()
{
//nog een tekstje dat de data is opgeslagen
Intent i = new Intent(this, overzicht.class);
startActivityForResult(i, ACTIVITY_OVERZICHT);
}
}




