logo
down
shadow

OnItemSelected Won't call when Spinner is getting arraylist from Firebase


OnItemSelected Won't call when Spinner is getting arraylist from Firebase

By : MOHAMMAD ZOBAIR
Date : November 17 2020, 03:01 PM
like below fixes the issue Eventually I have found an answer myself. Firebase functions works a-synchronically. I haven't found a way to change that - manipulate it somehow. The answer of working with data that is received from a firebase function is to initialize the desired function AFTER the for (gathering the information form the database) INSIDE onDataChange. for example:
code :
   public void restartAudioSpinner() {
    DatabaseReference database;
    database = FirebaseDatabase.getInstance().getReference("Audio Categories");

    database.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            categorylist = new ArrayList<String>();

            for (DataSnapshot data :dataSnapshot.getChildren()) {
                CategoryNew category = data.getValue(CategoryNew.class);
                categoriesList.add(new CategoryNew(category.getImageUrl(),category.getTitle()));
            }

            for (int i = 0; i < categoriesList.size(); i++) {
                categoriesTitle.add(categoriesList.get(i).getTitle());
            }
                 **// PUT THE DESIRED FUNCTION HERE!!!** EX: INIT THE SPINNER
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}


Share : facebook icon twitter icon
Call JSON on Spinner OnItemSelected and display data into another Spinner

Call JSON on Spinner OnItemSelected and display data into another Spinner


By : sharty
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Sorry about the late answer. I was solved this by my self but never came back here to post the solution which worked for me. Now I am posting this answer if any one has same kind of problem can get help from here.
So What I did
code :
    ArrayList<String> categories = new ArrayList<String>();
    try {
           JSONObject object = result.getJSONObject("result");
           JSONArray array = object.getJSONArray("data");

           for(int a = 0; a < array.length(); a++) {
                 String cityName = array.getJSONObject(a).getString("city_name");
                if(cityName.equals(selectedCity)) // this check is important
                {
                        categories.add(cityName );
                }
          }
         // after for loop ends populate adapter of second spinner 
         ArrayAdapter<String> adapt = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, categories);
         spinner2.setAdapter(adapt);
    }
    catch(Exception e) {
          e.printStackTrace();
    }
Display another arraylist element in textview using onItemSelected of a spinner

Display another arraylist element in textview using onItemSelected of a spinner


By : sandeep shukla
Date : March 29 2020, 07:55 AM
I wish this help you I have 2 arraylists, 1 is use to display the elements to the spinner and another one is use to display on a textview when one of the element from spinner is selected.
code :
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, 
    int position, long id) {
    switch(position){
      case 0: 
      textView1.setText(sportsList.get(0));
      break;
      case 1:
      textView2.setText(sportsList.get(1));
      break;
      case 2: 
      textView3.setText(sportsList.get(2));
       break;
    }
   }
});
Android Spinner will not launch OnItemSelected and current selected item is not displayed in Spinner

Android Spinner will not launch OnItemSelected and current selected item is not displayed in Spinner


By : user3433247
Date : March 29 2020, 07:55 AM
will help you Finally came across this which helped me, I changed my InitialSetupUI function to this:
code :
public void uniSpinnerSetup()
{
    ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
        public ParseQuery create() {
            ParseQuery query = new ParseQuery("University");
            return query;
        }
    };

    uniSpinner = (Spinner) findViewById(R.id.uniSpinner);

    ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(this, factory);
    adapter.setTextKey("name");
    uniSpinner.setAdapter(adapter);
    uniSpinner.setSelection(1);
    uniSpinner.setOnItemSelectedListener(new mySpinnerListener());
}
Change spinner options from spinner onItemSelected

Change spinner options from spinner onItemSelected


By : Sampada
Date : March 29 2020, 07:55 AM
seems to work fine In Xamarin.Android I always pass the spinnerItem, for example Android.Resource.Layout.SimpleSpinnerItem
code :
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(con, Android.Resource.Layout.SimpleSpinnerItem, newChapters);
How to fix Spinner not properly showing selected item after OnItemSelected call in fragment?

How to fix Spinner not properly showing selected item after OnItemSelected call in fragment?


By : MapTwo Za
Date : March 29 2020, 07:55 AM
wish of those help I finally figured it out!!! In the NFLSpinner.OnItemSelected call, once the user selected the new week, i was making a call to the MainActivity loadNFLScoreboard method which was creating a new instance of the Spinner on each call. I moved the NFLWeekSpinner declaration to outside the loadNFLScoreboad method and since there wasn't a new spinner being created on each call, the selected week properly displayed.
for all your help @lionscribe
Related Posts Related Posts :
  • Interrupt CompletableFuture with default value
  • Eclipse - Choosing servers in "Run on server" vs setting "Target Runtime"
  • Spring JPA doesn't validate bean on update
  • How is takeWhile different from filter?
  • Spring Scheduled Cron jobs firing at wrong time
  • JFrame window resizing on every compile. Different results every time
  • Kotlin unresolved reference :add after converting from Java code
  • How to use Neo4j APOC method " apoc.export.csv.query(query,file,config)" in Java program
  • Regex to include all spanish characters and number
  • Parsing and Mapping a JSON Object with Dynamic Properties
  • Which approach to building domain objects in Spring MVC is more correct?
  • Java Long Min and Max not exact as mentioned in docs
  • Selenium opens new tab after SendKeys
  • How to sort a large array of ints?
  • FitNessse Test can not find Fixture
  • Including Signed Libraries in Executable JAR with Maven
  • If and Else statement run on second iteration of while loop
  • Change class of disabled tab on change of dropdown value
  • Junit5 @ParameterizedTest How to pass array as one of parameter
  • Text message not being sent to a list of numbers but is sent when just one number is specified
  • Spring mapped servlet not called in jetty-maven-plugin
  • How to pace the consumption of a sqs queue using spring integration
  • Autowiring Not getting disabled using xml configuration
  • Maze solve and shortest path with Java BFS
  • Spinner updating only on user actions
  • Why are Java rules for protected access such as they are?
  • Modify parameter of method by value in annotation aspectJ
  • How to send sensitive data to a Liferay portlet from outside the Liferay portal
  • Does a server connection stay open if created inside a method?
  • JAR manifest Class-Path, use folder instead of jar
  • How to do a bulk update in Firestore
  • ItemArray.checklist.add() not appending string to ArrayList
  • How to move something on screen without other picture staying there
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org