how to get only keys from firebase and put it inside recyclerview












-1















i have this data structure to create bus schedules and provide the timings. i am not sure on how can i get the keys to get the timing



  "Schedules" : {
"Apu-to-vista" : {
"11:00" : "true",
"12:00" : "true",
"13:00" : "true",
"13:30" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:00" : "true",
"20:30" : "true"
},
"vista-to-apu" : {
"11:35" : "true",
"12:00" : "true",
"13:00" : "true",
"13:15" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:20" : "true",
"20:30" : "true"
}
}


I want to get the keys if i do mDatabase.getReference("Schedules").child("Apu-to-vista")



this is what i tried so far



    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

view = inflater.inflate(R.layout.vista, container, false);
mDatabase = FirebaseDatabase.getInstance();
fromAPU = mDatabase.getReference("Schedules").child("Apu-to-vista");
toAPU = mDatabase.getReference("Schedules").child("Vista-to-apu");
recyclerView = (RecyclerView) view.findViewById(R.id.fromAPURecycler);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);

adapter = new FirebaseRecyclerAdapter<Schedule, ViewHolder>(
Schedule.class, R.layout.card_view, ViewHolder.class, toAPU.orderByKey()
){
@Override
protected void populateViewHolder(ViewHolder viewHolder, Schedule model, int position) {
viewHolder.mTime.setText(getRef(position).getKey());
}
};
recyclerView.setAdapter(adapter);
return view;
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public final TextView mTime;

public ViewHolder(View itemView) {
super(itemView);
mTime = (TextView) itemView.findViewById(R.id.text_holder);

}
}


ive tried using firebase recycler adapter create the class consist of only String timeText, and putting it into recyclerview. however there is an error
the error said no adapter attached: skipping layout



i am just beginner in android, can someone help me. thank you










share|improve this question

























  • What does getRef(position).getKey() return?

    – Alex Mamo
    Nov 18 '18 at 11:44











  • i tried to logged it but it doesnt give me anything, since the error catched no adapter attached

    – Amam Mustofa
    Nov 18 '18 at 12:54











  • This is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

    – Alex Mamo
    Nov 19 '18 at 7:32
















-1















i have this data structure to create bus schedules and provide the timings. i am not sure on how can i get the keys to get the timing



  "Schedules" : {
"Apu-to-vista" : {
"11:00" : "true",
"12:00" : "true",
"13:00" : "true",
"13:30" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:00" : "true",
"20:30" : "true"
},
"vista-to-apu" : {
"11:35" : "true",
"12:00" : "true",
"13:00" : "true",
"13:15" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:20" : "true",
"20:30" : "true"
}
}


I want to get the keys if i do mDatabase.getReference("Schedules").child("Apu-to-vista")



this is what i tried so far



    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

view = inflater.inflate(R.layout.vista, container, false);
mDatabase = FirebaseDatabase.getInstance();
fromAPU = mDatabase.getReference("Schedules").child("Apu-to-vista");
toAPU = mDatabase.getReference("Schedules").child("Vista-to-apu");
recyclerView = (RecyclerView) view.findViewById(R.id.fromAPURecycler);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);

adapter = new FirebaseRecyclerAdapter<Schedule, ViewHolder>(
Schedule.class, R.layout.card_view, ViewHolder.class, toAPU.orderByKey()
){
@Override
protected void populateViewHolder(ViewHolder viewHolder, Schedule model, int position) {
viewHolder.mTime.setText(getRef(position).getKey());
}
};
recyclerView.setAdapter(adapter);
return view;
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public final TextView mTime;

public ViewHolder(View itemView) {
super(itemView);
mTime = (TextView) itemView.findViewById(R.id.text_holder);

}
}


ive tried using firebase recycler adapter create the class consist of only String timeText, and putting it into recyclerview. however there is an error
the error said no adapter attached: skipping layout



i am just beginner in android, can someone help me. thank you










share|improve this question

























  • What does getRef(position).getKey() return?

    – Alex Mamo
    Nov 18 '18 at 11:44











  • i tried to logged it but it doesnt give me anything, since the error catched no adapter attached

    – Amam Mustofa
    Nov 18 '18 at 12:54











  • This is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

    – Alex Mamo
    Nov 19 '18 at 7:32














-1












-1








-1








i have this data structure to create bus schedules and provide the timings. i am not sure on how can i get the keys to get the timing



  "Schedules" : {
"Apu-to-vista" : {
"11:00" : "true",
"12:00" : "true",
"13:00" : "true",
"13:30" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:00" : "true",
"20:30" : "true"
},
"vista-to-apu" : {
"11:35" : "true",
"12:00" : "true",
"13:00" : "true",
"13:15" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:20" : "true",
"20:30" : "true"
}
}


I want to get the keys if i do mDatabase.getReference("Schedules").child("Apu-to-vista")



this is what i tried so far



    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

view = inflater.inflate(R.layout.vista, container, false);
mDatabase = FirebaseDatabase.getInstance();
fromAPU = mDatabase.getReference("Schedules").child("Apu-to-vista");
toAPU = mDatabase.getReference("Schedules").child("Vista-to-apu");
recyclerView = (RecyclerView) view.findViewById(R.id.fromAPURecycler);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);

adapter = new FirebaseRecyclerAdapter<Schedule, ViewHolder>(
Schedule.class, R.layout.card_view, ViewHolder.class, toAPU.orderByKey()
){
@Override
protected void populateViewHolder(ViewHolder viewHolder, Schedule model, int position) {
viewHolder.mTime.setText(getRef(position).getKey());
}
};
recyclerView.setAdapter(adapter);
return view;
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public final TextView mTime;

public ViewHolder(View itemView) {
super(itemView);
mTime = (TextView) itemView.findViewById(R.id.text_holder);

}
}


ive tried using firebase recycler adapter create the class consist of only String timeText, and putting it into recyclerview. however there is an error
the error said no adapter attached: skipping layout



i am just beginner in android, can someone help me. thank you










share|improve this question
















i have this data structure to create bus schedules and provide the timings. i am not sure on how can i get the keys to get the timing



  "Schedules" : {
"Apu-to-vista" : {
"11:00" : "true",
"12:00" : "true",
"13:00" : "true",
"13:30" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:00" : "true",
"20:30" : "true"
},
"vista-to-apu" : {
"11:35" : "true",
"12:00" : "true",
"13:00" : "true",
"13:15" : "true",
"14:00" : "true",
"14:30" : "true",
"15:00" : "true",
"15:30" : "true",
"16:00" : "true",
"16:30" : "true",
"17:00" : "true",
"17:30" : "true",
"18:00" : "true",
"18:30" : "true",
"19:20" : "true",
"20:30" : "true"
}
}


I want to get the keys if i do mDatabase.getReference("Schedules").child("Apu-to-vista")



this is what i tried so far



    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

view = inflater.inflate(R.layout.vista, container, false);
mDatabase = FirebaseDatabase.getInstance();
fromAPU = mDatabase.getReference("Schedules").child("Apu-to-vista");
toAPU = mDatabase.getReference("Schedules").child("Vista-to-apu");
recyclerView = (RecyclerView) view.findViewById(R.id.fromAPURecycler);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);

adapter = new FirebaseRecyclerAdapter<Schedule, ViewHolder>(
Schedule.class, R.layout.card_view, ViewHolder.class, toAPU.orderByKey()
){
@Override
protected void populateViewHolder(ViewHolder viewHolder, Schedule model, int position) {
viewHolder.mTime.setText(getRef(position).getKey());
}
};
recyclerView.setAdapter(adapter);
return view;
}

public static class ViewHolder extends RecyclerView.ViewHolder {
public final TextView mTime;

public ViewHolder(View itemView) {
super(itemView);
mTime = (TextView) itemView.findViewById(R.id.text_holder);

}
}


ive tried using firebase recycler adapter create the class consist of only String timeText, and putting it into recyclerview. however there is an error
the error said no adapter attached: skipping layout



i am just beginner in android, can someone help me. thank you







java android firebase firebase-realtime-database android-recyclerview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 7:15







Amam Mustofa

















asked Nov 18 '18 at 5:09









Amam MustofaAmam Mustofa

247




247













  • What does getRef(position).getKey() return?

    – Alex Mamo
    Nov 18 '18 at 11:44











  • i tried to logged it but it doesnt give me anything, since the error catched no adapter attached

    – Amam Mustofa
    Nov 18 '18 at 12:54











  • This is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

    – Alex Mamo
    Nov 19 '18 at 7:32



















  • What does getRef(position).getKey() return?

    – Alex Mamo
    Nov 18 '18 at 11:44











  • i tried to logged it but it doesnt give me anything, since the error catched no adapter attached

    – Amam Mustofa
    Nov 18 '18 at 12:54











  • This is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

    – Alex Mamo
    Nov 19 '18 at 7:32

















What does getRef(position).getKey() return?

– Alex Mamo
Nov 18 '18 at 11:44





What does getRef(position).getKey() return?

– Alex Mamo
Nov 18 '18 at 11:44













i tried to logged it but it doesnt give me anything, since the error catched no adapter attached

– Amam Mustofa
Nov 18 '18 at 12:54





i tried to logged it but it doesnt give me anything, since the error catched no adapter attached

– Amam Mustofa
Nov 18 '18 at 12:54













This is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

– Alex Mamo
Nov 19 '18 at 7:32





This is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

– Alex Mamo
Nov 19 '18 at 7:32












1 Answer
1






active

oldest

votes


















0














To get the keys from Apu-to-vista:



fromAPU.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot apuToVistaSnapshot) {
for (DataSnapshot scheduleSnapshot : apuToVistaSnapshot.getChildren()){
String key = scheduleSnapshot.getKey();
// Do whatever you want with this key
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});


Firebase sends you the data wrapped in a DataSnapshotobject. After the call of addListenerForSingleValueEvent() on the fromAPU reference Firebase will send you the apuToVistaSnapshot which includes all the data of the "Apu-to-vista" node.



By calling getChildren() on that reference you can iterate through its child DataSnapshotinstances and get the key from each one.






share|improve this answer
























  • yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

    – Amam Mustofa
    Nov 19 '18 at 4:01











  • If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

    – Skemelio
    Nov 19 '18 at 10:49











  • Okay, thank you

    – Amam Mustofa
    Nov 20 '18 at 8:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358090%2fhow-to-get-only-keys-from-firebase-and-put-it-inside-recyclerview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To get the keys from Apu-to-vista:



fromAPU.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot apuToVistaSnapshot) {
for (DataSnapshot scheduleSnapshot : apuToVistaSnapshot.getChildren()){
String key = scheduleSnapshot.getKey();
// Do whatever you want with this key
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});


Firebase sends you the data wrapped in a DataSnapshotobject. After the call of addListenerForSingleValueEvent() on the fromAPU reference Firebase will send you the apuToVistaSnapshot which includes all the data of the "Apu-to-vista" node.



By calling getChildren() on that reference you can iterate through its child DataSnapshotinstances and get the key from each one.






share|improve this answer
























  • yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

    – Amam Mustofa
    Nov 19 '18 at 4:01











  • If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

    – Skemelio
    Nov 19 '18 at 10:49











  • Okay, thank you

    – Amam Mustofa
    Nov 20 '18 at 8:11
















0














To get the keys from Apu-to-vista:



fromAPU.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot apuToVistaSnapshot) {
for (DataSnapshot scheduleSnapshot : apuToVistaSnapshot.getChildren()){
String key = scheduleSnapshot.getKey();
// Do whatever you want with this key
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});


Firebase sends you the data wrapped in a DataSnapshotobject. After the call of addListenerForSingleValueEvent() on the fromAPU reference Firebase will send you the apuToVistaSnapshot which includes all the data of the "Apu-to-vista" node.



By calling getChildren() on that reference you can iterate through its child DataSnapshotinstances and get the key from each one.






share|improve this answer
























  • yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

    – Amam Mustofa
    Nov 19 '18 at 4:01











  • If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

    – Skemelio
    Nov 19 '18 at 10:49











  • Okay, thank you

    – Amam Mustofa
    Nov 20 '18 at 8:11














0












0








0







To get the keys from Apu-to-vista:



fromAPU.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot apuToVistaSnapshot) {
for (DataSnapshot scheduleSnapshot : apuToVistaSnapshot.getChildren()){
String key = scheduleSnapshot.getKey();
// Do whatever you want with this key
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});


Firebase sends you the data wrapped in a DataSnapshotobject. After the call of addListenerForSingleValueEvent() on the fromAPU reference Firebase will send you the apuToVistaSnapshot which includes all the data of the "Apu-to-vista" node.



By calling getChildren() on that reference you can iterate through its child DataSnapshotinstances and get the key from each one.






share|improve this answer













To get the keys from Apu-to-vista:



fromAPU.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot apuToVistaSnapshot) {
for (DataSnapshot scheduleSnapshot : apuToVistaSnapshot.getChildren()){
String key = scheduleSnapshot.getKey();
// Do whatever you want with this key
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});


Firebase sends you the data wrapped in a DataSnapshotobject. After the call of addListenerForSingleValueEvent() on the fromAPU reference Firebase will send you the apuToVistaSnapshot which includes all the data of the "Apu-to-vista" node.



By calling getChildren() on that reference you can iterate through its child DataSnapshotinstances and get the key from each one.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 '18 at 14:51









SkemelioSkemelio

753414




753414













  • yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

    – Amam Mustofa
    Nov 19 '18 at 4:01











  • If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

    – Skemelio
    Nov 19 '18 at 10:49











  • Okay, thank you

    – Amam Mustofa
    Nov 20 '18 at 8:11



















  • yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

    – Amam Mustofa
    Nov 19 '18 at 4:01











  • If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

    – Skemelio
    Nov 19 '18 at 10:49











  • Okay, thank you

    – Amam Mustofa
    Nov 20 '18 at 8:11

















yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

– Amam Mustofa
Nov 19 '18 at 4:01





yes, i tried to logged it and it works, however my next problem is how to put it into my adapter on recycler view

– Amam Mustofa
Nov 19 '18 at 4:01













If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

– Skemelio
Nov 19 '18 at 10:49





If you've tried and it works as you said, you should upvote to mark this answer as useful if not correct (where you should mark it as correct). This is how this community works.

– Skemelio
Nov 19 '18 at 10:49













Okay, thank you

– Amam Mustofa
Nov 20 '18 at 8:11





Okay, thank you

– Amam Mustofa
Nov 20 '18 at 8:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358090%2fhow-to-get-only-keys-from-firebase-and-put-it-inside-recyclerview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word