The use of the Android Spinner pull-down menu

Source: Internet
Author: User
Tags event listener json

1. layout file contents:

 <?xml version= "1.0" encoding= "Utf-8"?> "<linearlayout xmlns:android=" http:// Schemas.android.com/apk/res/android "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "an droid:orientation= "vertical" > <textview android:id= "@+id/target_number" Fill_parent "android:layout_height=" wrap_content "android:layout_marginleft=" 60SP "Android:layout_ margintop= "20SP" > </TextView> <spinner android:id= "@+id/target_pinner" android:layou T_width= "200SP" android:layout_height= "wrap_content" android:layout_marginleft= "60SP" Android:layo ut_margintop= "20SP" > </Spinner> <textview android:id= "@+id/consult_number" android:l Ayout_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_marginleft= "60SP" an
  droid:layout_margintop= "20SP" >  </TextView> <spinner android:id= "@+id/consult_spinner" android:layout_width= "200SP" android:layout_height= "Wrap_content" android:layout_marginleft= "60sp" android:layout_margintop= "20SP" &G
    T
        </Spinner> <button android:id= "@+id/manage_operation" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_marginleft= "100SP" android:layout_margintop= "20s" P "android:text=" android:textsize= "18SP" > </Button> </linearlayout> 

2.JAVA program code:

Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
Import java.util.ArrayList;

Import java.util.List;
Import Org.apache.http.HttpResponse;
Import Org.apache.http.HttpStatus;
Import Org.apache.http.NameValuePair;
Import org.apache.http.client.entity.UrlEncodedFormEntity;
Import Org.apache.http.client.methods.HttpPost;
Import org.apache.http.impl.client.DefaultHttpClient;
Import Org.apache.http.message.BasicNameValuePair;
Import Org.apache.http.protocol.HTTP;
Import Org.json.JSONArray;

Import Org.json.JSONObject;

Import Com.sxzichen.common.MD5Util;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.AdapterView;
Import Android.widget.AdapterView.OnItemSelectedListener;
Import Android.widget.ArrayAdapter;
Import Android.widget.Button;
Import Android.widget.Spinner;

Import Android.widget.TextView; public class Samequen_actiVity extends activity implements onclicklistener{private static final string[] queuinfo={"A01", "A02", "A03", "A04", "A0
    5 "," A06 "," A07 "," A08 "," A09 "," A10 "," A11 "};
    Private TextView Target_view;
    Private Spinner Target_spinner;
    
    Private arrayadapter&lt;string&gt; Target_adapter;
    Private TextView Consult_view;
    Private Spinner Consult_spinner;

    Private arrayadapter&lt;string&gt; Consult_adapter;
    Private String targetnumber= "";
    Private String consultmunber= "";
            @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub
            Super.oncreate (savedinstancestate);
            Setcontentview (R.LAYOUT.ACTIVITY_SAMEQUEU);
            Define the target queue number drop-down menu Target_view = (TextView) Findviewbyid (R.id.target_number);
            Target_spinner = (spinner) Findviewbyid (R.id.target_pinner); Connect the optional content to the arrayadapter target_adapter = new Arrayadapter&lt;string&gt; (this,android. R. Layout.simple_spinner_item,queuinfo); Set the style of the Drop-down list Target_adapter.setdropdownviewresource (Android.
            R.layout.simple_spinner_dropdown_item);
            Add the adapter to the spinner Target_spinner.setadapter (Target_adapter);
            Add Event Spinner Event Listener Target_spinner.setonitemselectedlistener (New Booldspinnerselectedlistener ());
            
            Set default value target_spinner.setvisibility (view.visible);
            Define the reference queue number Drop-down Menu Consult_view = (TextView) Findviewbyid (R.id.consult_number);
            Consult_spinner = (spinner) Findviewbyid (R.id.consult_spinner); Connect the optional content to the arrayadapter consult_adapter = new Arrayadapter&lt;string&gt; (this,android.
            R.layout.simple_spinner_item,queuinfo); Set the style of the Drop-down list Consult_adapter.setdropdownviewresource (Android.
            R.layout.simple_spinner_dropdown_item); Add adapter to spinner Consult_spinner.setadapter (Consult_adapter);
            Add Event Spinner Event Listener Consult_spinner.setonitemselectedlistener (New Moblespinnerselectedlistener ());
            
            Set default value consult_spinner.setvisibility (view.visible); 
            Button manage_operation= (button) Findviewbyid (r.id.manage_operation); 
            
    Manage_operation.setonclicklistener (this); ///Select target Queue number Event listener class Booldspinnerselectedlistener implements onitemselectedlistener{Publi
                      c void onitemselected (adapterview&lt;?&gt; arg0, View arg1, int arg2, long arg3) {

                     TARGETNUMBER=QUEUINFO[ARG2];
            Target_view.settext ("The queue number to move is:" +queuinfo[arg2]); public void onnothingselected (Adapterview&lt;?&gt; arg0) {}}///Select Reference Queue number Event Supervisor Listener class Moblespinnerselectedlistener implements onitemselectedlistener{public void onitemselected (Adapt Erview&lt;?&gt;
            	arg0, View arg1, int arg2, long arg3) {CONSULTMUNBER=QUEUINFO[ARG2];
            Consult_view.settext ("Move to" +queuinfo[arg2] + "behind"); public void onnothingselected (Adapterview&lt;?&gt; arg0) {}} @Override public V
		
		 OID OnClick (View v) {System.out.println ("Enter the same queue scheduling link");
System.out.println ("+targetnumber+" is moved to "+consultmunber+" after operation); Switch (V.getid ()) {//Click on a different button, pop-up the corresponding prompts////Jump-queue//Case r.id.breke_queuing://System.out.pri
Ntln ("Enter the queue");
Startbreakquening (User_name,estination_code); 
Break
Queue Management/Case r.id.same_queuing://System.out.println ("Enter the same queue management link");
Samemangerquening (User_name,estination_code);      
Break
Queue Management/Case r.id.diffrent_queuing://System.out.println ("Enter different queue management links"); DiffRentmangerquening (User_name,estination_code); 
Break  @Override public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu;
		Adds items to the action bar if it is present.
		Getmenuinflater (). Inflate (R.menu.activity_main, menu);
	return true; }
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.