Android Spinner 下拉列表

private Spinner spinner ;

private List<String> list ;

private ArrayAdapter<String> arrayAdapter ;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout. activity_main);

spinner=(Spinner) findViewById(R.id. spinner1);

list= new ArrayList<String>();

//NEW arrayAdapter适配器

arrayAdapter=new ArrayAdapter<String>(this ,android.R.layout.simple_spinner_dropdown_item, list);

//adapter设置下拉列表样式

arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter( arrayAdapter);

//设置监听器

spinner.setOnItemSelectedListener( new OnItemSelectedListener() {

@Override

public void onItemSelected(AdapterView<?> parent, View view,

int position, long id) {

}

@Override

public void onNothingSelected(AdapterView<?> arg0) {

}

});

}

时间: 2024-08-28 05:58:46

Android Spinner 下拉列表的相关文章

【转】Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)

原文网址:http://embed.21ic.com/software/android/201403/31603.html 1 :Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现) . 今天学习了Spinner组件,使用Spinner相当于从下拉列表中选择项目,下面演示一下Spinner的使用(分别使用ArrayAdapter和自定义Adapter实现) (一):使用ArrayAdapter进行适配数据: ①:首先定义一个布局文件: android:

Android之Socket通信、List加载更多、Spinner下拉列表

Android与服务器的通信方式主要有两种,一是Http通信,一是Socket通信.两者的最大差异在于,http连接使用的是“请求—响应方式”,即在请求时建立连接通道,当客户端向服务器发送请求后,服务器端才能向客户端返回数据.而Socket通信则是在双方建立起连接后就可以直接进行数据的传输,在连接时可实现信息的主动推送,而不需要每次由客户端想服务器发送请求. 那么,什么是socket?Socket又称套接字,在程序内部提供了与外界通信的端口,即端口通信.通过建立socket连接,可为通信双方的数

Android Spinner的五个部分

大家当看完这一片文章以后,我们就可以自定义spinner了,那大家还等什么我们就来看看吧.在Android的UI开发中,Spinner(下拉列表)总是可以用到的,一个简单的自定义Spinner制作我们只需要记住这重要的五步,一个Spinner就可以应用而生了.       (1)新建一个Android工程,名字为SpinnerTest.修改layout下的main.xml,添加一个Textview和一个Spinner,文件内容如下: < LinearLayout android:id="@

android Spinner 续

android Spinner 续 动态增删Spinner中的数据项 public class EX04_09 extends Activity{  private static final String[] countriesStr = { "北京市", "天津市", "上海市", "广州市" };  private TextView myTextView;  private EditText myEditText;  pr

Android Spinner(级联 天气预报)

activity_spinner.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_par

Android Spinner In Toolbar

As the title of the post suggest in this tutorial we will see how to have spinner widget inside the toolbar in the previous series of tutorial we have seen many example on how to set up the android spinner widget and also we have seen how to have and

Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)

public class MySpinnerActivity extends Activity { private Spinner spinner; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); spinner = (Spinner)findViewById(R.id

[转]Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)

今天学习了Spinner组件,使用Spinner相当于从下拉列表中选择项目,下面演示一下Spinner的使用(分别使用ArrayAdapter和自定义Adapter实现) (一):使用ArrayAdapter进行适配数据: ①:首先定义一个布局文件: 1 <span style="font-size:16px;"><?xml version="1.0" encoding="utf-8"?> 2 <LinearLayo

Android学习笔记之Spinner下拉列表使用案例

(1)两种方法提冲Spinner中的数据源:通过list集合,或者是通过xml文件进行配置 (2)布局代码例如以下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" andro