Is there a way I can use firebaseUI to populate spinner items like I would do with a ListView or a...












0















Using childevent listeners worked just fine for populating my spinner from my Firebase real time database but it's not as effective as using firebaseUI.
the documentation covers only recyclerview and listview, but I wanna use it for a spinner.



 Query query = FirebaseDatabase.getInstance().getReference("Labs");

FirebaseListOptions<Labs> options = new FirebaseListOptions.Builder<Labs>().setQuery(query, Labs.class).build();


FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(options) {
@Override
protected void populateView(@NonNull View v, @NonNull Labs model, int position) {

}


};

spinner.setAdapter(firebaseListAdapter);


I just don't know how to bind my model object with the view here.










share|improve this question

























  • What is happening when you are using this code? You don't have any code in your populateView method. Have you also started listening for changes?

    – Alex Mamo
    Nov 22 '18 at 11:55













  • @AlexMamo yeah, that's where my problem is. I've just been doing trial and error with the populateview method there, don't know how to bind it with my model class "Labs"

    – Jude Bobinihi
    Nov 22 '18 at 12:06











  • What is the error?

    – Alex Mamo
    Nov 22 '18 at 12:10











  • @AlexMamo I tried arraylist.model.getLabname(); no compile errors but app crashes on start of that activity

    – Jude Bobinihi
    Nov 22 '18 at 14:00













  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

    – Alex Mamo
    Nov 22 '18 at 14:03
















0















Using childevent listeners worked just fine for populating my spinner from my Firebase real time database but it's not as effective as using firebaseUI.
the documentation covers only recyclerview and listview, but I wanna use it for a spinner.



 Query query = FirebaseDatabase.getInstance().getReference("Labs");

FirebaseListOptions<Labs> options = new FirebaseListOptions.Builder<Labs>().setQuery(query, Labs.class).build();


FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(options) {
@Override
protected void populateView(@NonNull View v, @NonNull Labs model, int position) {

}


};

spinner.setAdapter(firebaseListAdapter);


I just don't know how to bind my model object with the view here.










share|improve this question

























  • What is happening when you are using this code? You don't have any code in your populateView method. Have you also started listening for changes?

    – Alex Mamo
    Nov 22 '18 at 11:55













  • @AlexMamo yeah, that's where my problem is. I've just been doing trial and error with the populateview method there, don't know how to bind it with my model class "Labs"

    – Jude Bobinihi
    Nov 22 '18 at 12:06











  • What is the error?

    – Alex Mamo
    Nov 22 '18 at 12:10











  • @AlexMamo I tried arraylist.model.getLabname(); no compile errors but app crashes on start of that activity

    – Jude Bobinihi
    Nov 22 '18 at 14:00













  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

    – Alex Mamo
    Nov 22 '18 at 14:03














0












0








0








Using childevent listeners worked just fine for populating my spinner from my Firebase real time database but it's not as effective as using firebaseUI.
the documentation covers only recyclerview and listview, but I wanna use it for a spinner.



 Query query = FirebaseDatabase.getInstance().getReference("Labs");

FirebaseListOptions<Labs> options = new FirebaseListOptions.Builder<Labs>().setQuery(query, Labs.class).build();


FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(options) {
@Override
protected void populateView(@NonNull View v, @NonNull Labs model, int position) {

}


};

spinner.setAdapter(firebaseListAdapter);


I just don't know how to bind my model object with the view here.










share|improve this question
















Using childevent listeners worked just fine for populating my spinner from my Firebase real time database but it's not as effective as using firebaseUI.
the documentation covers only recyclerview and listview, but I wanna use it for a spinner.



 Query query = FirebaseDatabase.getInstance().getReference("Labs");

FirebaseListOptions<Labs> options = new FirebaseListOptions.Builder<Labs>().setQuery(query, Labs.class).build();


FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(options) {
@Override
protected void populateView(@NonNull View v, @NonNull Labs model, int position) {

}


};

spinner.setAdapter(firebaseListAdapter);


I just don't know how to bind my model object with the view here.







java android xml firebase-realtime-database firebaseui






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 13:30









Aniruddh Parihar

2,19911027




2,19911027










asked Nov 22 '18 at 10:51









Jude BobinihiJude Bobinihi

187




187













  • What is happening when you are using this code? You don't have any code in your populateView method. Have you also started listening for changes?

    – Alex Mamo
    Nov 22 '18 at 11:55













  • @AlexMamo yeah, that's where my problem is. I've just been doing trial and error with the populateview method there, don't know how to bind it with my model class "Labs"

    – Jude Bobinihi
    Nov 22 '18 at 12:06











  • What is the error?

    – Alex Mamo
    Nov 22 '18 at 12:10











  • @AlexMamo I tried arraylist.model.getLabname(); no compile errors but app crashes on start of that activity

    – Jude Bobinihi
    Nov 22 '18 at 14:00













  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

    – Alex Mamo
    Nov 22 '18 at 14:03



















  • What is happening when you are using this code? You don't have any code in your populateView method. Have you also started listening for changes?

    – Alex Mamo
    Nov 22 '18 at 11:55













  • @AlexMamo yeah, that's where my problem is. I've just been doing trial and error with the populateview method there, don't know how to bind it with my model class "Labs"

    – Jude Bobinihi
    Nov 22 '18 at 12:06











  • What is the error?

    – Alex Mamo
    Nov 22 '18 at 12:10











  • @AlexMamo I tried arraylist.model.getLabname(); no compile errors but app crashes on start of that activity

    – Jude Bobinihi
    Nov 22 '18 at 14:00













  • If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

    – Alex Mamo
    Nov 22 '18 at 14:03

















What is happening when you are using this code? You don't have any code in your populateView method. Have you also started listening for changes?

– Alex Mamo
Nov 22 '18 at 11:55







What is happening when you are using this code? You don't have any code in your populateView method. Have you also started listening for changes?

– Alex Mamo
Nov 22 '18 at 11:55















@AlexMamo yeah, that's where my problem is. I've just been doing trial and error with the populateview method there, don't know how to bind it with my model class "Labs"

– Jude Bobinihi
Nov 22 '18 at 12:06





@AlexMamo yeah, that's where my problem is. I've just been doing trial and error with the populateview method there, don't know how to bind it with my model class "Labs"

– Jude Bobinihi
Nov 22 '18 at 12:06













What is the error?

– Alex Mamo
Nov 22 '18 at 12:10





What is the error?

– Alex Mamo
Nov 22 '18 at 12:10













@AlexMamo I tried arraylist.model.getLabname(); no compile errors but app crashes on start of that activity

– Jude Bobinihi
Nov 22 '18 at 14:00







@AlexMamo I tried arraylist.model.getLabname(); no compile errors but app crashes on start of that activity

– Jude Bobinihi
Nov 22 '18 at 14:00















If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

– Alex Mamo
Nov 22 '18 at 14:03





If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

– Alex Mamo
Nov 22 '18 at 14:03












2 Answers
2






active

oldest

votes


















0














There are two problems in your code. First, you are getting the following error:



layout cannot be null


Because you aren't assigning any layout in your populateView() method. In your code, this method is empty. So you should create a custom layout that can contain a TeexView for each element will help you solve this problem.



The second issue is that you are using FirebaseListAdapter but don't listen for changes anywhere. To solve this, please use the following line of code in your onStart() method:



firebaseListAdapter.startListening();


Don't also forget to remove it once is not needed by adding the following lines of code in your onStop() method:



if(firebaseListAdapter != null) {
firebaseListAdapter.stopListening();
}





share|improve this answer


























  • Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

    – Alex Mamo
    Nov 23 '18 at 8:51











  • although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

    – Jude Bobinihi
    Nov 23 '18 at 17:46











  • Just edited my answer. Cheers!

    – Alex Mamo
    Nov 23 '18 at 17:55











  • cheers, please help me upvote my initial question too

    – Jude Bobinihi
    Nov 23 '18 at 18:09



















0














You would have two options:
one is just initialize your ArrayAdapter by the list of data you got from query



ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,querylistData);
spinner.setAdapter(adapter);


Second you can bind data to the textview like below:



FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(this, Labs.class ,android.R.layout.simple_spinner_item, query) {
protected void populateView(View v,Lab model, int position)
{


((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());

}
};
spinner.setAdapter(firebaseListAdapter);





share|improve this answer


























  • the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

    – Jude Bobinihi
    Nov 22 '18 at 15:40













  • I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

    – Amir
    Nov 22 '18 at 16:07













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%2f53429309%2fis-there-a-way-i-can-use-firebaseui-to-populate-spinner-items-like-i-would-do-wi%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There are two problems in your code. First, you are getting the following error:



layout cannot be null


Because you aren't assigning any layout in your populateView() method. In your code, this method is empty. So you should create a custom layout that can contain a TeexView for each element will help you solve this problem.



The second issue is that you are using FirebaseListAdapter but don't listen for changes anywhere. To solve this, please use the following line of code in your onStart() method:



firebaseListAdapter.startListening();


Don't also forget to remove it once is not needed by adding the following lines of code in your onStop() method:



if(firebaseListAdapter != null) {
firebaseListAdapter.stopListening();
}





share|improve this answer


























  • Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

    – Alex Mamo
    Nov 23 '18 at 8:51











  • although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

    – Jude Bobinihi
    Nov 23 '18 at 17:46











  • Just edited my answer. Cheers!

    – Alex Mamo
    Nov 23 '18 at 17:55











  • cheers, please help me upvote my initial question too

    – Jude Bobinihi
    Nov 23 '18 at 18:09
















0














There are two problems in your code. First, you are getting the following error:



layout cannot be null


Because you aren't assigning any layout in your populateView() method. In your code, this method is empty. So you should create a custom layout that can contain a TeexView for each element will help you solve this problem.



The second issue is that you are using FirebaseListAdapter but don't listen for changes anywhere. To solve this, please use the following line of code in your onStart() method:



firebaseListAdapter.startListening();


Don't also forget to remove it once is not needed by adding the following lines of code in your onStop() method:



if(firebaseListAdapter != null) {
firebaseListAdapter.stopListening();
}





share|improve this answer


























  • Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

    – Alex Mamo
    Nov 23 '18 at 8:51











  • although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

    – Jude Bobinihi
    Nov 23 '18 at 17:46











  • Just edited my answer. Cheers!

    – Alex Mamo
    Nov 23 '18 at 17:55











  • cheers, please help me upvote my initial question too

    – Jude Bobinihi
    Nov 23 '18 at 18:09














0












0








0







There are two problems in your code. First, you are getting the following error:



layout cannot be null


Because you aren't assigning any layout in your populateView() method. In your code, this method is empty. So you should create a custom layout that can contain a TeexView for each element will help you solve this problem.



The second issue is that you are using FirebaseListAdapter but don't listen for changes anywhere. To solve this, please use the following line of code in your onStart() method:



firebaseListAdapter.startListening();


Don't also forget to remove it once is not needed by adding the following lines of code in your onStop() method:



if(firebaseListAdapter != null) {
firebaseListAdapter.stopListening();
}





share|improve this answer















There are two problems in your code. First, you are getting the following error:



layout cannot be null


Because you aren't assigning any layout in your populateView() method. In your code, this method is empty. So you should create a custom layout that can contain a TeexView for each element will help you solve this problem.



The second issue is that you are using FirebaseListAdapter but don't listen for changes anywhere. To solve this, please use the following line of code in your onStart() method:



firebaseListAdapter.startListening();


Don't also forget to remove it once is not needed by adding the following lines of code in your onStop() method:



if(firebaseListAdapter != null) {
firebaseListAdapter.stopListening();
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 17:55

























answered Nov 23 '18 at 8:50









Alex MamoAlex Mamo

44.6k82862




44.6k82862













  • Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

    – Alex Mamo
    Nov 23 '18 at 8:51











  • although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

    – Jude Bobinihi
    Nov 23 '18 at 17:46











  • Just edited my answer. Cheers!

    – Alex Mamo
    Nov 23 '18 at 17:55











  • cheers, please help me upvote my initial question too

    – Jude Bobinihi
    Nov 23 '18 at 18:09



















  • Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

    – Alex Mamo
    Nov 23 '18 at 8:51











  • although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

    – Jude Bobinihi
    Nov 23 '18 at 17:46











  • Just edited my answer. Cheers!

    – Alex Mamo
    Nov 23 '18 at 17:55











  • cheers, please help me upvote my initial question too

    – Jude Bobinihi
    Nov 23 '18 at 18:09

















Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

– Alex Mamo
Nov 23 '18 at 8:51





Good to hear that it worked :) In this case, please consider accepting my answer by clicking the checkmark (✔️) on the left side under the vote arrows. Should change the color in green. I'd appreciate it. Thanks!

– Alex Mamo
Nov 23 '18 at 8:51













although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

– Jude Bobinihi
Nov 23 '18 at 17:46





although, that layout didn't work. I had to create a layout with Textviews for each database element I wanted.

– Jude Bobinihi
Nov 23 '18 at 17:46













Just edited my answer. Cheers!

– Alex Mamo
Nov 23 '18 at 17:55





Just edited my answer. Cheers!

– Alex Mamo
Nov 23 '18 at 17:55













cheers, please help me upvote my initial question too

– Jude Bobinihi
Nov 23 '18 at 18:09





cheers, please help me upvote my initial question too

– Jude Bobinihi
Nov 23 '18 at 18:09













0














You would have two options:
one is just initialize your ArrayAdapter by the list of data you got from query



ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,querylistData);
spinner.setAdapter(adapter);


Second you can bind data to the textview like below:



FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(this, Labs.class ,android.R.layout.simple_spinner_item, query) {
protected void populateView(View v,Lab model, int position)
{


((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());

}
};
spinner.setAdapter(firebaseListAdapter);





share|improve this answer


























  • the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

    – Jude Bobinihi
    Nov 22 '18 at 15:40













  • I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

    – Amir
    Nov 22 '18 at 16:07


















0














You would have two options:
one is just initialize your ArrayAdapter by the list of data you got from query



ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,querylistData);
spinner.setAdapter(adapter);


Second you can bind data to the textview like below:



FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(this, Labs.class ,android.R.layout.simple_spinner_item, query) {
protected void populateView(View v,Lab model, int position)
{


((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());

}
};
spinner.setAdapter(firebaseListAdapter);





share|improve this answer


























  • the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

    – Jude Bobinihi
    Nov 22 '18 at 15:40













  • I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

    – Amir
    Nov 22 '18 at 16:07
















0












0








0







You would have two options:
one is just initialize your ArrayAdapter by the list of data you got from query



ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,querylistData);
spinner.setAdapter(adapter);


Second you can bind data to the textview like below:



FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(this, Labs.class ,android.R.layout.simple_spinner_item, query) {
protected void populateView(View v,Lab model, int position)
{


((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());

}
};
spinner.setAdapter(firebaseListAdapter);





share|improve this answer















You would have two options:
one is just initialize your ArrayAdapter by the list of data you got from query



ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,querylistData);
spinner.setAdapter(adapter);


Second you can bind data to the textview like below:



FirebaseListAdapter<Labs> firebaseListAdapter = new FirebaseListAdapter<Labs>(this, Labs.class ,android.R.layout.simple_spinner_item, query) {
protected void populateView(View v,Lab model, int position)
{


((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());

}
};
spinner.setAdapter(firebaseListAdapter);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 16:03

























answered Nov 22 '18 at 13:05









AmirAmir

161214




161214













  • the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

    – Jude Bobinihi
    Nov 22 '18 at 15:40













  • I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

    – Amir
    Nov 22 '18 at 16:07





















  • the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

    – Jude Bobinihi
    Nov 22 '18 at 15:40













  • I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

    – Amir
    Nov 22 '18 at 16:07



















the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

– Jude Bobinihi
Nov 22 '18 at 15:40







the second option generated a no layout error, i fixed it, but then the spinner doesn't show any data now, I don't quite understand the "querylistdata" in the first

– Jude Bobinihi
Nov 22 '18 at 15:40















I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

– Amir
Nov 22 '18 at 16:07







I mean by querlistdata is the list of data you are getting from Firebasedatabase and you want to display in spinner. For second option, I have already edited the code above and you just follow the code and just try this code. hope it show spinner with data

– Amir
Nov 22 '18 at 16:07




















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%2f53429309%2fis-there-a-way-i-can-use-firebaseui-to-populate-spinner-items-like-i-would-do-wi%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

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]