我正在嘗試使用mAltText在玻璃屏幕上顯示我的高度。當我調用卡類時,它給了我錯誤:「構造函數卡(new LocationHelper.LocationResult(){})未定義」,因爲我有「this」作爲參數。我應該使用什麼來代替「this」才能使其工作?我一整天都在搜索一個可行的例子,但無濟於事。Google Glass Card構造函數未定義
任何人都可以提供一些建議給新手||我應該使用android textview而不是卡片,然後將XML充填到視圖中?
LocationHelper是另一個.java文件中的另一個類。
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);
}
}
謝謝!這很好,我知道這很簡單。這源於我對「背景」究竟是什麼的有限瞭解。你救了我那天的朋友。 – Autex 2014-10-06 02:59:53
@Autex非常受歡迎。快樂的編碼! – pt2121 2014-10-06 03:00:40