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 9270707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:26:12+00:00 2026-06-18T15:26:12+00:00

In my app i have a spinner with two items ..i have to choose

  • 0

In my app i have a spinner with two items ..i have to choose the item an do action accordingly

    dialogButton.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {

                        String Comment = edittext.getText().toString();
                           String choose = spinner.getSelectedItem()
                                    .toString();
                             if (Comment != null && Comment.equalsIgnoreCase("")){
                            post(Comment,choose);
                            getActivity().finish();

                             }else{
                                 showToast("Please enter you comment!");

                             }  
                    }
                });
                dialog.show();
                dialog.getWindow().setAttributes(lp);

            } catch (Exception e) {
                e.printStackTrace();
                getActivity().finish();
            }
        }

        private void post(String comments, String choose) throws Exception{

            StringBuffer finalMessage = new StringBuffer("\nRecomends " + Data.getfName());
            if(Data.getAddress() != null && !Data.getAddress().isEmpty()){
                finalMessage.append("\n" + Data.getAddress());
            }

----------------->      if(spinner.getSelectedItem().toString().equals("Post to personal directory & FB")){
        Bundle params = new Bundle();
        params.putString("message",finalMessage.toString() );
        publishStory(params,comments);

    }else {
         try {
                new FBUtils(activity).sharePlaces(attractionData, comments, null);
            } catch (Exception e) {
                Log.e(TAG,"sharePlaces error ",e);
            }
    }
        }

        private void publishStory(Bundle postParams,final String comments,final String choose) {
            Session session = Session.getActiveSession();

            if (session != null){
        List<String> permissions = session.getPermissions();
                    if (!isSubsetOf(PERMISSIONS, permissions)) {
                        Session.NewPermissionsRequest newPermissionsRequest = new Session
                                .NewPermissionsRequest(this, PERMISSIONS);
                    session.requestNewPublishPermissions(newPermissionsRequest);

                    }
                    Request.Callback callbackRequest= new Request.Callback() {
                        public void onCompleted(Response response) {
                            if (response == null || response.equals("")
                                    || response.equals("false")) {
                                showToast("Blank response.");
                            } else  


                                new fbUtils(activity).share(Data, comments, response.getError(),choose);
                            } catch (Exception e) {
                                Log.e(TAG,"sharePlaces error ",e);
                            }
                            }

                    };
                    Request request = new Request(session, Constants.fb.fbId + "/comments", postParams, 
                                          HttpMethod.POST, callbackRequest);

                    RequestAsyncTask task = new RequestAsyncTask(request);
                    task.execute();


                }

the issue is the post() is not executing when clicking the dailogbutton its going into else part, i want to execute the if condition in post() method, Any help is appreciated

  • 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-18T15:26:13+00:00Added an answer on June 18, 2026 at 3:26 pm

    As you are getting the value from the spinner. The value may not be updated one .

    You should use item-selected listeners.

    String result=””;

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                    @Override
                   public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
          Toast.makeText(parent.getContext()), "The planet is " +
              parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
    // Your variable should update here 
    result = parent.getItemAtPosition(pos).toString();
        }
    
    
    
                    @Override
                    public void onNothingSelected(AdapterView<?> parentView) {
                        // your code here
                    }
    
                });
    

    Now use that value in onPost method as:

    private void post(String comments, String choose) throws Exception{
    
                StringBuffer finalMessage = new StringBuffer("\nRecomends " + Data.getfName());
                if(Data.getAddress() != null && !Data.getAddress().isEmpty()){
                    finalMessage.append("\n" + Data.getAddress());
                }
    Log.v("TEST",spinner.getSelectedItem().toString());
    ----------------->      if(result.equals("Post to personal directory &#38; FB")){
            Bundle params = new Bundle();
            params.putString("message",finalMessage.toString() );
            publishStory(params,comments);
    
        }else {
             try {
                    new FBUtils(activity).sharePlaces(attractionData, comments, null);
                } catch (Exception e) {
                    Log.e(TAG,"sharePlaces error ",e);
                }
        }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app, I have a Spinner , that can be filled with two
i have a spinner an two buttons on my Android app, the spinner is
I created an app and have been testing it against targetSdk 14. The spinner
I have an app where the user presses a button and a custom spinner
my app have action bar on top of windows. Where are some buttons. Buttons
I have been slowing learning and building my first android app. I'm VERY new
Within an Android app I am developing, I have a spinner where you can
Hi i have to develop one spinner app. here how can i remove the
In my app I have a spinner in which the user selects a number.
I have been following the tutorial for adding spinner items to a spinner control

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.