首先,代码对我来说很好。数据是从firebase中精确检索我希望在顶部看到最后插入的数据。但它正在反向模式。这是检索的代码。
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.sonalirod.alwayswhite.Model.ADeposit;
import java.util.ArrayList;
import java.util.List;
public class admininterface extends AppCompatActivity {
Button adminlogin, sh,retu;
List<ADeposit> abc;
DatabaseReference databaseBazars;
public ListView deposit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admininterface);
databaseBazars= FirebaseDatabase.getInstance().getReference("Deposit");
adminlogin = (Button) findViewById(R.id.adminlogin);
sh = (Button) findViewById(R.id.adminshow);
deposit = (ListView) findViewById(R.id.listview_deposit);
retu=(Button)findViewById(R.id.returnbuttonn);
abc = new ArrayList<>();
deposit.setVisibility(View.GONE);
retu.setVisibility(View.GONE);
adminlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), ALogin.class);
startActivity(i);
}
});
sh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sh.setVisibility(View.GONE);
adminlogin.setVisibility(View.GONE);
deposit.setVisibility(View.VISIBLE);
retu.setVisibility(View.VISIBLE);
}
});
retu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sh.setVisibility(View.VISIBLE);
adminlogin.setVisibility(View.VISIBLE);
retu.setVisibility(View.GONE);
deposit.setVisibility(View.GONE);
}
});
}
@Override
protected void onStart() {
super.onStart();
databaseBazars.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
abc.clear();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
ADeposit ks = ds.getValue(ADeposit.class);
abc.add(ks);
}
DepositList adapter = new DepositList(admininterface.this, abc);
deposit.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
在那里,组最后插入数据库。但它是所有数据的底部。但我希望最后插入的数据最重要。如果您还告诉我如何通过日期(如11月,12月)对数据进行排序,那将是我的荣幸。
它不重复。请看一下我的代码。我想在这里有两个排序事件,一个是降序(最新将在顶部),另一个是月份排序。