android 的 Spinner 下拉菜单的使用
2013-02-22 16:02:35 来源:WEB开发网核心提示:2.JAVA程序代码:import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpResponse;i
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) { } } @Override public 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; // } } @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; } }
更多精彩
赞助商链接