I am trying to display my altitude on Glass' screen using mAltText. When I call the card class, it gives me the error: "The constructor Card(new LocationHelper.LocationResult(){}) is undefined" because I have "this" as a parameter. What should I use instead of "this" in order for it to work? I have searched all day for a working example to no avail.
Can anyone offer some advice to a newbie || should I use the android textview instead of card and then inflate an XML to the view?
LocationHelper is another class in another .java file.
public class MainActivity extends Activity {
private String mAltText;
LocationResult locationResult;
LocationHelper locationHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.locationResult = new LocationResult(){
@Override
public void gotLocation(Location location){
if(location!=null){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
double altitude = location.getAltitude();
mAltText = (Double.toString(altitude));
// display on card
Card card = new Card(this); //Error: The constructor Card(new LocationHelper.LocationResult(){}) is undefined
card.setText(mAltText);
View cardView = card.getView();
setContentView(cardView);
}else{
Log.e(TAG, "Location is null.");
}
}
};
this.locationHelper = new LocationHelper();
this.locationHelper.getLocation(this, this.locationResult);
}
}
Card constructor takes Context as you can see here.
So, you can pass any variable that is a subclass of Context. In your case, Activity is a good choice.
Card card = new Card(MainActivity.this);
In your code, you can't just use this
because this
refers to LocationResult and it's not Context.
Can anyone offer some advice to a newbie || should I use the android textview instead of card and then inflate an XML to the view?
You can have a text view in a card. FYI, Card API is replaced by CardBuilder. If you don't have any special requirement or custom view, you can go with CardBuilder.