Android's spinner Pull-down menu implements cascading _android

Source: Internet
Author: User
Tags event listener

The effect chart is as follows:

The default load is the first time

Select the original queue:

Cascading Effect Chart:

Critical code to the Drop-down list select event Listener binding ID:

Copy Code code as follows:

int pos = Firsthand_dlbh_pinner.getselecteditemposition ();
Firsthand_pdbh_adapter = new Arrayadapter<string> (context,
Android. R.layout.simple_spinner_item, Queu_info[pos]);
Firsthand_pdbh_spinner.setadapter (Firsthand_pdbh_adapter);

Complete code:

Layout file Code:

Copy Code code as follows:

<?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"
android:orientation= "Vertical" >

<textview
Android:id= "@+id/firsthand_dlbh"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_marginleft= "60SP"
android:layout_margintop= "20SP" >
</TextView>

    <spinner
        android:id= "@+id/firsthand_dlbh_ Pinner "
        android:layout_width=" 200SP
         android:layout_height= "Wrap_content"
        android: layout_marginleft= "60SP"
        android:layout_margintop= "20SP"
    </spinner>

    <textview
         android:id= "@+id/firsthand_pdbh"
        android:layout_width = "Fill_parent"
        android:layout_height= "wrap_content"
         android:layout_marginleft= "60SP"
         android:layout_margintop= "20sp"
    </textview>

<spinner
Android:id= "@+id/firsthand_pdbh_pinner"
Android:layout_width= "200SP"
android:layout_height= "Wrap_content"
android:layout_marginleft= "60SP"
android:layout_margintop= "20SP" >
</Spinner>

<textview
Android:id= "@+id/target_dlbh"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_marginleft= "60SP"
android:layout_margintop= "20SP" >
</TextView>

    <spinner
        android:id= "@+id/target_dlbh_ Spinner "
        android:layout_width=" 200SP
         android:layout_height= "Wrap_content"
        android: layout_marginleft= "60SP"
        android:layout_margintop= "20SP"
    </spinner>

<button
Android:id= "@+id/diff_manage_operation"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginleft= "100SP"
android:layout_margintop= "20SP"
android:text= "Execution Schedule"
Android:textsize= "18SP" >
</Button>

</LinearLayout>


JAVA Program code:
Copy Code code as follows:

Import android.app.Activity;
Import Android.content.Context;

Import Android.os.Bundle;

Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.AdapterView;
Import Android.widget.ArrayAdapter;
Import Android.widget.Button;
Import Android.widget.Spinner;
Import Android.widget.TextView;
Import Android.widget.AdapterView.OnItemSelectedListener;

Public class Manageinfo_activity extends activity implements Onclicklistener {
 private context;
 private static final string[] Queuilist = {"A999", "B888"};
 private static final string[] Default_linfo = {"A01", "A02", "A03", "A04",
    "A05", "A06", " A07 "," A08 "," A09 "," A10 "," A11 "};
 private static final string[][] Queu_info = new string[][] {
   {"A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08", "A09",
      "A10", "A11"},
   {"B01", "B02 "," B03 "," B04 "," B05 "," B06 "," B07 "," B08 "," B09 ",
     " B10 "," B11 "};
 private TextView Firsthand_dlbh_view;
 private Spinner Firsthand_dlbh_pinner;
 private arrayadapter<string> firsthand_dlbh_adapter;

Private TextView Firsthand_pdbh_view;
Private Spinner Firsthand_pdbh_spinner;
Private arrayadapter<string> Firsthand_pdbh_adapter;

Private TextView Target_dlbh_view;
Private Spinner Target_dlbh_spinner;
Private arrayadapter<string> Target_dlbh_adapter;

Private String firsthand_dlbh = "";
Private String FIRSTHAND_PDBH = "";
Private String target_dlbh = "";

@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_manageinfo);

context = this;

  //defines the original queue number Drop-down menu
  firsthand_dlbh_view = (TextView) Findviewbyid (R.ID.FIRSTHAND_DLBH);
  firsthand_dlbh_pinner = (Spinner) Findviewbyid (R.id.firsthand_dlbh_pinner);
  //connect the optional content to arrayadapter
  firsthand_dlbh_adapter = new Arrayadapter<string> ( This,
    android. R.layout.simple_spinner_item, queuilist);
  //Sets the style of the Drop-down list
  firsthand_dlbh_adapter
    . Setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);
  //Add adapter to spinner
  firsthand_dlbh_pinner.setadapter (firsthand_dlbh_adapter);
  //Add an event spinner event to listen for
  firsthand_dlbh_pinner
    . Setonitemselectedlistener (New Firsthanddlbhspinnerselectedlistener ());
  //Sets the default value
  firsthand_dlbh_pinner.setvisibility (view.visible);

  //defines the original queued numbering drop-down menu
  firsthand_pdbh_view = (TextView) Findviewbyid (R.ID.FIRSTHAND_PDBH);
  firsthand_pdbh_spinner = (spinner) Findviewbyid (R.id.firsthand_pdbh_pinner);
  //connect the optional content to arrayadapter
  firsthand_pdbh_adapter = new Arrayadapter<string> ( This,
    android. R.layout.simple_spinner_item, Default_linfo);
  //Sets the style of the Drop-down list
  firsthand_pdbh_adapter
    . Setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);
  //Add adapter to spinner
  firsthand_pdbh_spinner.setadapter (Firsthand_pdbh_adapter) ;
  //Add event Spinner Event listener
  firsthand_pdbh_spinner
    . Setonitemselectedlistener (New Firsthandpdbhspinnerselectedlistener ());
  //Sets the default value
  firsthand_pdbh_spinner.setvisibility (view.visible);

  //defines the destination queue drop-down menu
  target_dlbh_view = (TextView) Findviewbyid (R.ID.TARGET_DLBH);
  target_dlbh_spinner = (spinner) Findviewbyid (R.id.target_dlbh_spinner);
  //connect the optional content to arrayadapter
  target_dlbh_adapter = new Arrayadapter<string> (this ,
    android. R.layout.simple_spinner_item, queuilist);
  //Sets the style of the Drop-down list
  target_dlbh_adapter
    . Setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);
  //Add adapter to spinner
  target_dlbh_spinner.setadapter (target_dlbh_adapter);
  //Add an event spinner event to listen for
  target_dlbh_spinner
    . Setonitemselectedlistener (New Targetdlbhpinnerselectedlistener ());
  //Sets the default value
  target_dlbh_spinner.setvisibility (view.visible);

Button diff_manage_operation = (button) Findviewbyid (r.id.diff_manage_operation);
Diff_manage_operation.setonclicklistener (this);

}

Select target Queue number event listener
Class Firsthanddlbhspinnerselectedlistener Implements
Onitemselectedlistener {

public void onitemselected (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
FIRSTHAND_DLBH = Queuilist[arg2];
Firsthand_dlbh_view.settext ("Select the original queue is:" + queuilist[arg2]);
int pos = Firsthand_dlbh_pinner.getselecteditemposition ();
Firsthand_pdbh_adapter = new Arrayadapter<string> (context,
Android. R.layout.simple_spinner_item, Queu_info[pos]);
Firsthand_pdbh_spinner.setadapter (Firsthand_pdbh_adapter);

}

public void onnothingselected (adapterview<?> arg0) {
}
}

Select target Queue number event listener
Class Firsthandpdbhspinnerselectedlistener Implements
Onitemselectedlistener {

public void onitemselected (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
FIRSTHAND_PDBH = (String) firsthand_pdbh_spinner
. Getitematposition (ARG2);
Firsthand_pdbh_view.settext ("The queue number to move is:"
+ (String) firsthand_pdbh_spinner.getitematposition (arg2));
}

public void onnothingselected (adapterview<?> arg0) {
}
}

Select reference Queue number Event listener
Class Targetdlbhpinnerselectedlistener implements Onitemselectedlistener {

public void onitemselected (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
TARGET_DLBH = Queuilist[arg2];
Target_dlbh_view.settext ("Move to" + Queuilist[arg2] + "queue");
}

public void onnothingselected (adapterview<?> arg0) {
}
}


@Override
public void OnClick (View v) {

System.out.println ("Into the same queue scheduling link");

System.out.println ("Execute the queue number" + Firsthand_pdbh + "from" + firsthand_dlbh
+ "Move to" + TARGET_DLBH + "End of queue operation");
Diffmangerquening (user_name, Estination_code, FIRSTHAND_DLBH, FIRSTHAND_DLBH,TARGET_DLBH); Switch (V.getid ()) {//Click on a different button, pop-up corresponding prompts


}

@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This 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.