代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
动态添加删除Spinner
作者:
千如
/ 发布于
2015/5/25
/
689
SpinnerActivity package cn.dccssq; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; 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.EditText; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; public class SpinnerActivity extends Activity implements Button.OnClickListener, Spinner.OnItemSelectedListener { private TextView show_yourChoice_TextView; private EditText input_City_EditText; private Button Add_Button, Del_Button; private Spinner city_Spinner; private ArrayAdapter<String> arrayAdapter; private String[] cities; private String addString; private List<String> cityList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); show_yourChoice_TextView = (TextView) findViewById(R.id.TextView_Show_yourChoice); input_City_EditText = (EditText) findViewById(R.id.EditView_Input); Add_Button = (Button) findViewById(R.id.Button_ADD); Del_Button = (Button) findViewById(R.id.Button_DEL); city_Spinner = (android.widget.Spinner) findViewById(R.id.cityItems); cities = new String[] { "Android", "BlackBerry", "J2ME", "Symbian", "Broncho", "LinuxMobile", "Palm", "WindwosMobile" }; cityList = new ArrayList<String>(); for (int i = 0; i < cities.length; i++) { cityList.add(cities[i]); } arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cityList); arrayAdapter .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); city_Spinner.setAdapter(arrayAdapter); show_yourChoice_TextView.setText(arrayAdapter.getItem(0)); city_Spinner.setSelection(0); Add_Button.setOnClickListener((OnClickListener) this); Del_Button.setOnClickListener((OnClickListener) this); city_Spinner.setOnItemSelectedListener((OnItemSelectedListener) this); } public void onClick(View arg0) { // TODO Auto-generated method stub switch (arg0.getId()) { case R.id.Button_ADD: Toast.makeText(this, "ADD", Toast.LENGTH_SHORT).show(); addString = input_City_EditText.getText().toString(); for (int i = 0; i < arrayAdapter.getCount(); i++) { if (addString.equals(arrayAdapter.getItemId(i))) { return; } } if (!addString.equals("")) { arrayAdapter.add(addString); int post = arrayAdapter.getPosition(addString); city_Spinner.setSelection(post); input_City_EditText.setText(""); } break; case R.id.Button_DEL: if (city_Spinner.getSelectedItem() != null) { arrayAdapter.remove(city_Spinner.getSelectedItem().toString()); input_City_EditText.setText(""); if (arrayAdapter.getCount() == 0) { Toast.makeText(this, "DELETE", Toast.LENGTH_SHORT).show(); show_yourChoice_TextView.setText(""); } } break; default: break; } } public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub show_yourChoice_TextView.setText(arrayAdapter.getItem(arg2)); } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add("Exit"); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub finish(); return super.onOptionsItemSelected(item); } } main.xml <LinearLayout android:id="@+id/widget92" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:id="@+id/TextView_Show_yourChoice" android:layout_width="190px" android:layout_height="wrap_content" android:text="TextView" android:textSize="25sp" android:layout_gravity="center_horizontal" /> <EditText android:id="@+id/EditView_Input" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="18sp"> </EditText> <Button android:id="@+id/Button_ADD" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ADD"> </Button> <Button android:id="@+id/Button_DEL" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="DELETE"> </Button> <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/cityItems"> </Spinner> </LinearLayout>
试试其它关键字
Spinner
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
千如
贡献的其它代码
(
9
)
.
Android发送接收短信
.
Android打电话
.
用户注册的Activity
.
动态添加删除Spinner
.
记事本程序
.
取得已安装程序列表
.
访问webservice
.
html5中页面拨打电话的方式
.
如何获wifi路由器的BSSID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3