は変更されません。最も古い。私はref.orderByKey
とQuery refQuery = ref.orderByKey();
で直接処理しようとしていましたが、動作していないようです。アンドロイドfirebase orderByKeyは、私は今、2日間を探していたが、firebaseトピックは本当に悪い私はにnewestから重みを取得するためにfirebase DBからの私のデータをソートしたい</p> <p>を推測する議論されているもの
キーはyy:MM:dd
の形式の日付ですが、そのコードではデータがどのような方法でもソートされていません...何か助けてください。
final Firebase ref = new Firebase("https://myapp.com/" + FirebaseAuth.getInstance().getCurrentUser().getUid() + "/weight/");
ref.orderByKey().addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
weights = new Double[(int)snapshot.getChildrenCount()];
dates = new String[(int)snapshot.getChildrenCount()];
Toast.makeText(getActivity(), "Wczytuje Pierwsze Dane"+snapshot.getValue(), Toast.LENGTH_LONG).show();
int i = 0;
for (DataSnapshot child : snapshot.getChildren()) {
weights[i] = child.getValue(Double.class);
dates[i] = child.getKey();
weightMap.put(child.getKey(), child.getValue(Double.class));
i++;
}
testowy.setText(""+weightMap.size());
if(weightMap.size()>1)
diffValue.setText(""+(weights[weightMap.size()-1] - weights[weightMap.size()-2]));
WeightListAdapter weightList = new WeightListAdapter(weightMap);
ListView weightListView = (ListView) view.findViewById(R.id.weightList);
weightListView.setAdapter(weightList);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
編集1:
ref.orderByKey().addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
weights = new Double[(int)snapshot.getChildrenCount()];
dates = new String[(int)snapshot.getChildrenCount()];
int i = 0;
for (DataSnapshot child : snapshot.getChildren()) {
weights[i] = child.getValue(Double.class);
dates[i] = dt.format(Long.parseLong(child.getKey()));
weightMap.put(child.getKey(), child.getValue(Double.class));
i++;
}
私はquestion.Theスナップショットを明確にするための日付を変換せずに立っていたソートされていないしています。なぜ...?
編集2: あなたは私に尋ねた何本か?
最後に、それは働いた。よくやった :)。 –