如何从Firebase检索已排序的数据并在文本视图中显示它? (JAVA)

时间:2017-06-22 21:19:32

标签: java android firebase firebase-realtime-database

我尝试在Android Studio中从FireBase收集数据,同时使用orderByChild和equalTo函数对其进行排序。然后我试图在文本视图上显示数据。页面每次都崩溃了。我怎样才能解决这个问题?我已经给出了我的代码和我的数据库:

public class TrackOrder extends AppCompatActivity {
    DatabaseReference mDatabase;
    private EditText trackText;
    private Button trackBtn;
    private TextView disp, text;

    public void trackBtn (View view){ //opens the admin portal activity
        trackText = (EditText) findViewById(R.id.trackText);
        disp = (TextView) findViewById(R.id.disp);
        String trackNumb = trackText.getText().toString();
        disp.setText(trackNumb);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_track_order);

        String numb = disp.getText().toString();

        trackText = (EditText) findViewById(R.id.trackText);
        text = (TextView) findViewById(R.id.text);
        trackBtn = (Button) findViewById(R.id.trackBtn);

        mDatabase = FirebaseDatabase.getInstance().getReference().child("Orders"); //Reflecting where the data will be located
        mDatabase.orderByChild("1 order_number").equalTo("4725");
        mDatabase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
               String name = dataSnapshot.getValue().toString();
                text.setText(name);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
}

The Database format

0 个答案:

没有答案