android 的 Spinner 下拉式功能表的使用

來源:互聯網
上載者:User

1.布局檔案內容 :

<?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/target_number"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="60sp"        android:layout_marginTop="20sp" >    </TextView>    <Spinner        android:id="@+id/target_pinner"        android:layout_width="200sp"        android:layout_height="wrap_content"        android:layout_marginLeft="60sp"        android:layout_marginTop="20sp" >    </Spinner>    <TextView        android:id="@+id/consult_number"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="60sp"        android: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" >    </Spinner>    <Button        android:id="@+id/manage_operation"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginLeft="100sp"        android:layout_marginTop="20sp"        android:text="執行調度"        android:textSize="18sp" >    </Button></LinearLayout>

2.JAVA程式碼:

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","A05","A06","A07","A08","A09","A10","A11"};    private TextView target_view ;    private Spinner target_spinner;    private ArrayAdapter<String> target_adapter;        private TextView consult_view;    private Spinner consult_spinner;    private ArrayAdapter<String> 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);            //定義目標排隊編號下拉式功能表            target_view = (TextView) findViewById(R.id.target_number);            target_spinner = (Spinner) findViewById(R.id.target_pinner);            //將可選內容與ArrayAdapter串連起來            target_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,queuinfo);            //設定下拉式清單的風格            target_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);            //將adapter 添加到spinner中            target_spinner.setAdapter(target_adapter);            //添加事件Spinner事件監聽              target_spinner.setOnItemSelectedListener(new BooldSpinnerSelectedListener());            //設定預設值            target_spinner.setVisibility(View.VISIBLE);                        //定義參照排隊編號下拉式功能表            consult_view = (TextView) findViewById(R.id.consult_number);            consult_spinner = (Spinner) findViewById(R.id.consult_spinner);            //將可選內容與ArrayAdapter串連起來            consult_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,queuinfo);            //設定下拉式清單的風格            consult_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);            //將adapter 添加到spinner中            consult_spinner.setAdapter(consult_adapter);            //添加事件Spinner事件監聽              consult_spinner.setOnItemSelectedListener(new MobleSpinnerSelectedListener());            //設定預設值            consult_spinner.setVisibility(View.VISIBLE);                        Button manage_operation=(Button)findViewById(R.id.manage_operation);             manage_operation.setOnClickListener(this);                 }        //選擇 目標排隊編號 事件 監聽器    class BooldSpinnerSelectedListener implements OnItemSelectedListener{            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,                            long arg3) {                      targetNumber=queuinfo[arg2];                     target_view.setText("要移動的排隊編號是:"+queuinfo[arg2]);            }            public void onNothingSelected(AdapterView<?> arg0) {            }    }    //    //選擇 參照排隊編號 事件 監聽器    class MobleSpinnerSelectedListener implements OnItemSelectedListener{            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,                            long arg3) {                     consultMunber=queuinfo[arg2];            consult_view.setText("移動到 "+queuinfo[arg2] +" 後邊 ");            }            public void onNothingSelected(AdapterView<?> arg0) {            }    }    @Overridepublic void onClick(View v) { System.out.println(" 進入同一隊列調度環節"); System.out.println("執行 把 "+targetNumber+" 移動到 "+consultMunber+"  後邊操作  ");//   switch(v.getId()){//根據點擊不同的按鈕,彈出相應的提示 //   // 插隊//        case R.id.breke_queuing: //        System.out.println("進入插隊環節");//        startBreakQuening(user_name,estination_code) ;//            break; //            //隊列管理//        case R.id.same_queuing: //        System.out.println("進入同一隊列管理環節");//        sameMangerQuening(user_name,estination_code) ;//            break;      //            //隊列管理//        case R.id.diffrent_queuing: //        System.out.println("進入不同隊列管理環節");//         diffrentMangerQuening(user_name,estination_code) ;//            break; //   }        }     @Overridepublic 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;}}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.