Implementation of cascading in the menu of android Spinner

Source: Internet
Author: User

As follows:

First load by default

Select the original queue:

Cascade:

Key code: bind Id to the selected event listener in the drop-down list:

Copy codeThe Code is 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 codeThe Code is 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 scheduling"
Android: textSize = "18sp">
</Button>

</LinearLayout>

JAVA program code:
Copy codeThe Code is 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 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;

// Define 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 available content with the ArrayAdapter
Firsthand_dlbh_adapter = new ArrayAdapter <String> (this,
Android. R. layout. simple_spinner_item, queuilist );
// Set the style of the drop-down list
Firsthand_dlbh_adapter
. SetDropDownViewResource (android. R. layout. simple_spinner_dropdown_item );
// Add the adapter to the spinner
Firsthand_dlbh_pinner.setAdapter (firsthand_dlbh_adapter );
// Add event Spinner event listening
Firsthand_dlbh_pinner
. SetOnItemSelectedListener (new FirsthanddlbhSpinnerSelectedListener ());
// Set the default value
Firsthand_dlbh_pinner.setVisibility (View. VISIBLE );

// Define the drop-down menu of the original queue number
Firsthand_pdbh_view = (TextView) findViewById (R. id. firsthand_pdbh );
Firsthand_pdbh_spinner = (Spinner) findViewById (R. id. firsthand_pdbh_pinner );
// Connect the available content with the ArrayAdapter
Firsthand_pdbh_adapter = new ArrayAdapter <String> (this,
Android. R. layout. simple_spinner_item, default_linfo );
// Set the style of the drop-down list
Firsthand_pdbh_adapter
. SetDropDownViewResource (android. R. layout. simple_spinner_dropdown_item );
// Add the adapter to the spinner
Firsthand_pdbh_spinner.setAdapter (firsthand_pdbh_adapter );
// Add event Spinner event listening
Firsthand_pdbh_spinner
. SetOnItemSelectedListener (new FirsthandpdbhSpinnerSelectedListener ());
// Set the default value
Firsthand_pdbh_spinner.setVisibility (View. VISIBLE );

// Define the drop-down menu of the target queue
Target_dlbh_view = (TextView) findViewById(R.id.tar get_dlbh );
Target_dlbh_spinner = (Spinner) findViewById(R.id.tar get_dlbh_spinner );
// Connect the available content with the ArrayAdapter
Target_dlbh_adapter = new ArrayAdapter <String> (this,
Android. R. layout. simple_spinner_item, queuilist );
// Set the style of the drop-down list
Target_dlbh_adapter
. SetDropDownViewResource (android. R. layout. simple_spinner_dropdown_item );
// Add the adapter to the spinner
Target_dlbh_spinner.setAdapter (target_dlbh_adapter );
// Add event Spinner event listening
Target_dlbh_spinner
. SetOnItemSelectedListener (new TargetdlbhpinnerSelectedListener ());
// Set 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 the target queuing 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 as follows:" + 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 the target queuing 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 queuing number to be moved is :"
+ (String) firsthand_pdbh_spinner.getItemAtPosition (arg2 ));
}

Public void onNothingSelected (AdapterView <?> Arg0 ){
}
}

/// Select the event listener with reference to the queuing number
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 ("entering the same queue scheduling stage ");

System. out. println ("Run the queuing number" + firsthand_pdbh + "slave" + firsthand_dlbh
+ "Move the queue to" + target_dlbh + "operation at the end of the queue ");
// DiffMangerQuening (user_name, estination_code, firsthand_dlbh, firsthand_dlbh, target_dlbh); // switch (v. getId () {// the corresponding prompt is displayed based on the button clicked.

}

@ 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.