关闭

下拉框

245人阅读 评论(0) 收藏 举报




在MainActivity   中:


public class MainActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	
	String[] start=this.getResources().getStringArray(R.array.citys_start);
	final String[] target=this.getResources().getStringArray(R.array.citys_target);
	
	Spinner spinner1=(Spinner) findViewById(R.id.spinner1);
	ArrayAdapter adapter1=new ArrayAdapter(this, android.R.layout.simple_list_item_1,android.R.id.text1,start);
	
	spinner1.setAdapter(adapter1);
	spinner1.setBackgroundColor(Color.GRAY);
	spinner1.setSelection(0);
	
	Spinner spinner2=(Spinner) findViewById(R.id.spinner2);
	ArrayAdapter adapter2=new ArrayAdapter(this, android.R.layout.simple_list_item_1,android.R.id.text1,target);
	spinner2.setAdapter(adapter2);
	spinner2.setBackgroundColor(Color.GRAY);
	spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
				int pos, long id) {
			Toast.makeText(getApplicationContext(), target[pos], Toast.LENGTH_SHORT).show();
			
			
		}

		@Override
		public void onNothingSelected(AdapterView<?> parent) {
		}
	
		
	});
	}
}

在values 中创建一个arrys   





0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:243982次
    • 积分:4188
    • 等级:
    • 排名:第8304名
    • 原创:167篇
    • 转载:126篇
    • 译文:0篇
    • 评论:35条
    最新评论