Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:33:24+00:00 2026-06-14T10:33:24+00:00

Is it possible to create warning message when spinner item is changed but in

  • 0

Is it possible to create warning message when spinner item is changed but in case user click’s No
selection should be canceled and selected item should stay as it was previously. If I store last selected spinner item and pass it to spinner when user chooses No
it will tirger onItemSelectedListener which i don’t want to.

I tried to use OnTouchListener but this doesn’t help because spinner list is displayed imidiately after spinner is touched.

See my code below for better understanding.

    spinnerSearch.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, final int position, long id) {

            if (!ShoppingCart.isEmpty()) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(SearchProductActivity.this);
                dialog.setMessage("Selecting new finacier will empty your basket.").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        //do some work
                        //storing lastSelectedFinancier
                    }

                }).setNegativeButton("No", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {

                        dialog.dismiss();
                        //cancel selection
                        //spinnerSearch.setSelection(lastSelectedFinancier)

                    }

                });

                AlertDialog alert = dialog.show();

                TextView messageView = (TextView) alert.findViewById(android.R.id.message);
                messageView.setGravity(Gravity.CENTER);
            } else {
                //do some other work
                //lastSelectedFinancier
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }

        //lastSelectedFinancier

    });

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:33:25+00:00Added an answer on June 14, 2026 at 10:33 am

    I have found workaround for this problem. Instead of spinner I used textbox (whit spinner style) and combine it with alert dialog for creating list.
    Maybe it is not best solution but it worked for me :)))

    public class SpinnerItem {

    String spinnerText;
    String value;
    
    public SpinnerItem(String text, String value) {
        this.spinnerText = text;
        this.value = value;
    }
    
    public String getSpinnerText() {
        return spinnerText;
    }
    
    public String getValue() {
        return value;
    }
    
    public String toString() {
        return spinnerText;
    }
    


    public class SearchProductActivity extends BaseActivity {

    private EditText txtSearch;
    private ListView listProducts;
    private Button btnShoppingCart;
    private EditText txtSelectFinancier;
    private DevRestHelper rest;
    private ListOfProducts adapter;
    public static String financierRelationNumber;
    private int numberOfItemsInBasket = 0;
    
    private List<ProductModel> products = new ArrayList<ProductModel>();
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_product);
    
        initControls();
        getProjectSupplier();
        financierRelationNumber = String.valueOf(OrderData.Financiers.get(0).RelationNumber);
        txtSelectFinancier.setText(String.valueOf(OrderData.Financiers.get(0).Name));
        GetProducts(financierRelationNumber);
        setButtonActions();
        ShoppingCart.ProductOwnerId = getProjectSupplier().get(0).getValue();
        ShoppingCart.ProductOwner = getProjectSupplier().get(0).getSpinnerText();
    
    }
    
        private void initControls() {
        btnShoppingCart = (Button) findViewById(R.id.activity_search_product_btnShoppingCart);
        listProducts = (ListView) findViewById(R.id.activity_search_product_listProducts);
        txtSearch = (EditText) findViewById(R.id.activity_search_product_txtName);
        txtSelectFinancier = (EditText) findViewById(R.id.activity_search_product_txtFinancier);
    
    }
    
    private void setButtonActions() {
    
        txtSelectFinancier.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                if (!ShoppingCart.isEmpty()) {
                    AlertDialog.Builder dialog = new AlertDialog.Builder(SearchProductActivity.this);
                    dialog.setMessage(getString(R.string.err_selecting_new_finacier_will_empty_your_basket)).setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
    
                        public void onClick(DialogInterface dialog, int which) {
                            listDialog(SearchProductActivity.this, "", getProjectSupplier(), txtSelectFinancier);
                            listProducts.setAdapter(null);
                            ShoppingCart.emptyCartItems();
                            ShoppingCart.ProductOwner = txtSelectFinancier.getText().toString();
    
                        }
                    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
    
                        public void onClick(DialogInterface dialog, int which) {
    
                            dialog.dismiss();
                        }
    
                    });
    
                    AlertDialog alert = dialog.show();
    
                    TextView messageView = (TextView) alert.findViewById(android.R.id.message);
                    messageView.setGravity(Gravity.CENTER);
    
                } else
                    listDialog(SearchProductActivity.this, "", getProjectSupplier(), txtSelectFinancier);
            }
        });
    
    }
    
        private List<SpinnerItem> getProjectSupplier() {
    
        List<SpinnerItem> items = new ArrayList<SpinnerItem>();
    
        for (DetermineFinanciersModel finaciers : OrderData.Financiers) {
            items.add(new SpinnerItem(finaciers.Name, String.valueOf(finaciers.RelationNumber)));
        }
    
        return items;
    
    }
    
    private void listDialog(Context context, String title, final List<SpinnerItem> list, final TextView control) {
    
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);
    
        List<String> strings = new ArrayList<String>();
    
        for (SpinnerItem spinnerItem : list) {
            strings.add(spinnerItem.getSpinnerText());
        }
    
        final CharSequence[] items = strings.toArray(new String[strings.size()]);
    
        builder.setItems(items, new DialogInterface.OnClickListener() {
    
            public void onClick(DialogInterface dialog, int selectedItem) {
                control.setText(list.get(selectedItem).getSpinnerText());
                ShoppingCart.ProductOwnerId = list.get(selectedItem).getValue();
                GetProducts(list.get(selectedItem).getValue());
            }
        });
    
        AlertDialog alert = builder.create();
        alert.show();
    
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Unable to create the virtual machine Warning during installation of WP8 SDK:
Is it possible to add Bullet points for the warning/Alert message box for a
Is possible create an extension for SQL Management Studio in Visual Studio 2010? Visual
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create provisioning profile in iphone application i developed my iphone app and
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am
Possible Duplicate: Create an alert on any view controller after Facebook request:didFailWithError: I have
Possible Duplicate: Create Excel file in Java How to save output in excel format
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.