logo
down
shadow

How the Spinner setSelection() works?


How the Spinner setSelection() works?

By : Akram
Date : November 22 2020, 02:42 PM
hope this fix your issue Why do you get the same field for different variables?
Project11=c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project)); Project22=c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
code :
Details WD = new Details();

//read the first row
c.moveToNext();
Project11=c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
addProject1(Project11);
WD.setProject(Project11); // dont know what does this method do

//read the second row
c.moveToNext();
Project22=c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
addProject2(Project22);
WD.setProject(Project22);

c.close();

Log.e("TAG1",Project11);
Log.e("TAG2",Project22);
    int rowNum=1;
    while(c.moveToNext()) {

        switch (rowNum) {
            case 1:
                //handle first row
                Project11 = c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
                addProject1(Project11);
                WD.setProject(Project11); // dont know what does this method do
                break;

            case 2:
                //handle second row
                Project22 = c.getString.........
                break;
            case 3:
                //handle third
                break;
        //  etc....
        }

        rowNum+=1;
    }
 case 3:
                        Project33 = c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
            if(project33.equals("")) // detect if no selection made
            {
                            addProject3("Pro-XXX-XXX"); // set value
                            WD.setProject("Pro-XXX-XXX");
            }
            else
            {
                            addProject3(Project33);
                            WD.setProject(Project33);
            }
                        break;
public void addProject1(String l)
{

    String[] arr = new String[]{"Pro-XXX-XXX","TRN-XXX-XXX","SRV-XXX-XXX","PRO-REE-BERGARDING","PRO-SKM-SSS","PRO-SKM-DI","PRO-SKM-PACKING","PRO-SIE-AVAGO_S110",
            "PRO-SIE-BIOCON","PRO-BCM-T13/T17","TRIN-IN_HOUSE","TRIN-EXTERNAL","SRIV-SIE-LEMONGRASS","SRV-PW-SIMOCODE","SRV-REE-SIMOCODE","PRO-SKM-D5","PRO-SKM-DRIOU","PRO-BKI-DESMET",
            "PRO-BKI-INFINEON","PRO-INH-ANDROID","PRO-BCM-S120","PRO-GAW-OP"};
    List<String> list = new ArrayList<String>();

    list.addAll(Arrays.asList(arr)); // add all of the arr elements to the list

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, list);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    project1.setAdapter(adapter);

    project1.setSelection(list.indexOf("l")); // get the index of the l string in the arr, then select that index in the spinner
}


Share : facebook icon twitter icon
Android Spinner view: difference between setSelection (int position) and setSelection (int position, boolean animate)?

Android Spinner view: difference between setSelection (int position) and setSelection (int position, boolean animate)?


By : Raj
Date : March 29 2020, 07:55 AM
I hope this helps . Well it should be doing what the name suggests. animating from the current position to the desired position. when you use just setSelection the change is more apropriate when you are trying to make sure the user sees the change (sort of a notification of a change) plus it looks smoother. at least that's why i use it. as for the animating i never had any issues with it.
why are you using the savedPosition instead of position for the selection? maybe that's what is causing the loop. my suggestion is to try to do it with position and see if it fails. your code is somewhat odd..
Spinner setSelection() not work

Spinner setSelection() not work


By : user3387350
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Have you tried to set the spinner by using two arguments, the second using a boolean:
code :
detailsOptionSpinner.setSelection(finalCount, true); 
setSelection(int position, boolean animate)
//Jump directly to a specific item in the adapter data.
SetSelection on a spinner crashes when layout_weight is assigned to spinner

SetSelection on a spinner crashes when layout_weight is assigned to spinner


By : csafonov
Date : March 29 2020, 07:55 AM
like below fixes the issue I have done a simplified experiment to identify where I am having this problem. It was a long question with a lot of code earlier. Now I have kept a small and simple code:
code :
spin1.setSelection(0);  //does not crash
spin1.setSelection(getResources().getStringArray(R.array.feet).length - 1); 
spin1.setSelection(0, true); 
spin1.setSelection(getResources().getStringArray(R.array.feet).length - 1, true); 
Spinner.SetSelection(0) resets second Spinner in Xamarin.Android

Spinner.SetSelection(0) resets second Spinner in Xamarin.Android


By : Marc de Wit
Date : March 29 2020, 07:55 AM
I hope this helps you . I found a solution for a my issue. It's probably a hack solution, but since none could figure out how to solve this, this has to do for now:
code :
public Spinner spinner1;
public Spinner spinner2;

public enum Spinners {
    Spinner1, Spinner2, None
}

public Types SelectedSpinner;
public bool IsChangingSpinner;

public void Init() {
    SelectedSpinner = Spinners.None;
    IsChangingSpinner = false;

    List<string> items = new List<string>();

    //Populate dta into Items for Adapter
    foreach(Data d in datas)
    {
        items.Add(d.ToString());
    }

    var adapter1 = new ArrayAdapter<string>(this, Resource.Layout.spinner_item, items);
    adapter1.SetDropDownViewResource(Resource.Layout.spinner_item);
    spinner1.Adapter = adapter;
    spinner1.ItemSelected += spinner1_ItemSelected;

    var adapter2 = new ArrayAdapter<string>(this, Resource.Layout.spinner_item, items);
    adapter2.SetDropDownViewResource(Resource.Layout.spinner_item);
    spinner2.Adapter = adapter;
    spinner2.ItemSelected += spinner2_ItemSelected;
}


public void spinner1_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) {
    if(IsChangingSpinner == false) {
        Spinner spinner = (Spinner)sender;
        string value = spinner.GetItemAtPosition(e.Position).ToString();
        //Use value ...

        //Reset spinner2
        IsChangingSpinner = true;
        spinner2.SetSelection(0);

        if(SelectedSpinner == Spinners.Spinner1) {
            IsChangingSpinner = false;
        }

        SelectedSpinner = Spinners.Spinner1;

    } else {
        IsChangingSpinner = false;
    }
}

public void spinner2_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) {
    if(IsChangingSpinner == false) {
        Spinner spinner = (Spinner)sender;
        string value = spinner.GetItemAtPosition(e.Position).ToString();
        //Use value ...

        //Reset spinner1
        IsChangingSpinner = true;
        spinner1.SetSelection(0);

        if(SelectedSpinner == Spinners.Spinner2) {
            IsChangingSpinner = false;
        }

        SelectedSpinner = Spinners.Spinner2;
    } else {
        IsChangingSpinner = false;
    }

}
Spinner methods (setSelection) not working for only one spinner in activity

Spinner methods (setSelection) not working for only one spinner in activity


By : user3637220
Date : March 29 2020, 07:55 AM
Hope this helps Put your setSelection before setting adapter.
After seeing your code you forgot to put the second parameter of setSelection().
code :
setSelection(boardNumber - 7, true)
Related Posts Related Posts :
  • Search specific nearby places using google places api web services for android
  • How to update app?
  • Is It possible to develop app with react native and make changes in android studio?
  • How to create Motion Splash Screen in Android?
  • Build Gradle Android studio Build Slow
  • Using Android DownloadManager,how do i get file name?
  • Android - How to Load More then 20mb Image in Imageview
  • Notification is not cancelled after calling notification.cancel
  • How to implement the smart-crop feature
  • Null Pointer exception on reading SMS stored in SIM in Android
  • remove google text from google maps in android
  • Image captured from camera not displaying in imageview android
  • kivy: My screenmanager code is not working with scrollview
  • Dynamic MpAndroidChart Not Working
  • Yandex Maps return 403 Forbidden using retrofit
  • how set selected spinner item in android studio?
  • Does Picasso library for Android handle image loading while network connectivity is off?
  • colorAccent in Holo Theme
  • Android: animation on layout after button clicked for minimum SDK version of 14
  • Are static variable truly "global" (system-wide) in Android?
  • How to create android snackbar with custom layout
  • Animate a car(Marker) along a path in google map android
  • Default to "compass" (gyroscope) mode when viewing a photosphere
  • Gradle - finished with non-zero exit value 1
  • Android Studio 2.0 Application crash on unmodified Application class
  • Android Studio cursor display error
  • Creating Dagger 2 component to be shared between src/test and src/androidTest
  • Android losing state when screen is OFF and ON again
  • Android Notification.Builder addAction PendingIntent Fragment
  • Use another button instead of back button
  • Android Studio Send string over socket after taking a picture [Google Glass]
  • Realm `access from incorrect thread` error when using shared code between IntentService and AsyncTask (Android)
  • osmdroid plotting current location offline
  • GifAnimationDrawable(Gif file) not playing in ListView
  • Controlling emission of Observable items in unit tests
  • android: Log in Button
  • Gradle github and facebook dependencies can't resolve
  • How can you animate a view back and forth between two states on Android, while supporting backpressure?
  • $(LOCAL_PATH) not returning the path to current directory correctly
  • Error:Cause: com.android.sdklib.repository.FullRevision
  • How to get an offset in RecyclerView ItemDecorator
  • Android toolbar home button not showing
  • TextView keeps popping up
  • Toolbar overlaps below status bar
  • Inflated view not updating
  • Errors of the Manifest
  • How to perform the same operation on several elements in array in doInBackground()
  • see error when use getSupportActionBar().setDisplayHomeAsUpEnabled(true)
  • What the heck is going on with this animation?
  • How to set the color of the counter on a TextInputLayout?
  • Cannot resolve symbol 'GeoJsonLayer '
  • Font file not loading on Libgdx Android
  • Simulate GCM push notifications on Android
  • Google maps provider, Wifi, 3g and GPS
  • Textview animation error
  • I want my FAB to stay at the bottom of the screen
  • How to attach multiple Images with a note taking app in android?
  • How to share xml layout using Intent.ACTION_SEND
  • Is there a default selector for the RecyclerView
  • Cordova SQLite Plugin not functioning with Android Studio
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co