我目前正在研究JavaFX基本程序。
我有一个TableView,其中包含一个行侦听器:
private void accessGoogleFit() {
mClient = new GoogleApiClient.Builder(mContext)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.CONFIG_API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
//fetch data
new FetchStepsAsync().execute();
}
@Override
public void onConnectionSuspended(int i) {
if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
Log.i("TAG1", "Connection lost,Cause: network lost");
} else if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
Log.i("TAG1", "Connection lost, service disconnected");
}
}
}).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult result) {
Log.i("TAG1", "Connection failed. Cause:" + result.toString());
if (!result.hasResolution()) {
//show the localized error dialog
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), getActivity(), 0).show();
return;
}
//the failure has a resolution
if (!authInProcess) {
try {
Log.i("TAG1", "Attempting to resolve failed connection");
authInProcess = true;
result.startResolutionForResult(getActivity(), GOOGLE_FIT_PERMISSIONS_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
Log.e("TAG1", "Exception while starting resolution activity", e);
}
}
}
})
.build();
mClient.connect();
}
private class FetchStepsAsync extends AsyncTask<Object, Object, Long> {
protected Long doInBackground(Object... params) {
long total = 0;
PendingResult<DailyTotalResult> result = Fitness.HistoryApi.readDailyTotal(mClient, DataType.TYPE_STEP_COUNT_DELTA);
DailyTotalResult totalResult = result.await(30, TimeUnit.SECONDS);
if (totalResult.getStatus().isSuccess()) {
DataSet totalSet = totalResult.getTotal();
if (totalSet != null) {
total = totalSet.isEmpty() ? 0 : totalSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS).asInt();
}
} else {
Log.w("TAG1", "There was a problem getting the step count.");
}
return total;
}
@Override
protected void onPostExecute(Long aLong) {
super.onPostExecute(aLong);
//Total steps
Log.i("TAG1", "Total steps:" + aLong);
edSteps.setText(aLong.toString());
}
}
然后我得到一个“刷新”按钮,它清除了我的表视图,并在其中放了新数据之后:
id name student(boolean) teachers
1 John 0 null
2 Mary 0 null
3 Frank 1 ,1,2,
这里是错误:
// Detecte row click
Lodger.getSelectionModel().selectedItemProperty().addListener((obs, oldvalue, newvalue)->{
civility.getSelectionModel().select(newvalue.getGenre());
txtLodgerName.setText(newvalue.getNom());
txtLodgerFirstName.setText(newvalue.getPrénom());
if(newvalue.getAge() == 0) {
txtLodgerAge.setText("");
} else {
txtLodgerAge.setText(String.valueOf(newvalue.getAge()));
}
txtLodgerJob.setText(newvalue.getProfession());
txtLodgerAdresse.setText(newvalue.getAdresse());
txtLodgerAdresse2.setText(newvalue.getAdresse_comp());
txtLodgerVille.setText(newvalue.getVille());
txtLodgerHomePhone.setText(newvalue.getNum_fixe());
txtLodgerPhone.setText(newvalue.getNum_mobile());
txtLodgerEmail.setText(newvalue.getEmail());
txtLodgerDateE.setText(newvalue.getDate_entree());
txtLodgerDateS.setText(newvalue.getDate_sortie());
txtLodgerObservation.setText(newvalue.getObservation());
txtLodgerFiability.setText(newvalue.getFiabilite());
});
如果有人有相同的错误,请说出来,如果我找到答案,我会给出答案。 谢谢您的帮助!
PS:如果您需要更多详细信息,请说我将尝试添加新数据