Android基础TOP4_2:弹窗式选择列表
Activity:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.top4_4.MainActivity" >
<TextView
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:layout_height="30dp"
android:paddingLeft="5dp"
android:background="#FFA500"
android:text="Spinner" />
<Spinner
android:id="@+id/sp"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:layout_height="30dp"
android:paddingLeft="5dp"
android:text=""
/>
</LinearLayout>
JAVApublic class MainActivity extends Activity private Spinner sp;
private TextView tv;
private ArrayAdapter aa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//定义数据源
String []balls=new String[]{"","足球","篮球","棒球"};
sp=(Spinner) findViewById(R.id.sp);
tv=(TextView) findViewById(R.id.tv);
//找到数据源
aa=new ArrayAdapter<String>
(this,android.R.layout.simple_spinner_item,balls);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//给Spinner赋值数据
sp.setAdapter(aa);
//当点击时弹出选择列表
sp.setOnItemSelectedListener(new OnItemSelectedListener() { @Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub //给TextView选中的数据
tv.setText(aa.getItem(position).toString());
} @Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
tv.setText("没有选中任何数据!");
}
});


Android基础TOP4_2:弹窗式选择列表的更多相关文章
- Android Spinner值不显示,选择列表正常
你在给adapter设置数据时,如果你是静态数据,也就是死数据,那么spinner显示没有问题,但是你如果异步进行网络请求,或者使用Volley请求的时候就要注意,你的adapter设置要在onRes ...
- Android基础-系统架构分析,环境搭建,下载Android Studio,AndroidDevTools,Git使用教程,Github入门,界面设计介绍
系统架构分析 Android体系结构 安卓结构有四大层,五个部分,Android分四层为: 应用层(Applications),应用框架层(Application Framework),系统运行层(L ...
- 深入理解gradle编译-Android基础篇
深入理解gradle编译-Android基础篇 导读 Gradle基于Groovy的特定领域语言(DSL)编写的一种自动化建构工具,Groovy作为一种高级语言由Java代码实现,本文将对Gradle ...
- Android基础之用Eclipse搭建Android开发环境和创建第一个Android项目(Windows平台)
一.搭建Android开发环境 准备工作:下载Eclipse.JDK.Android SDK.ADT插件 下载地址:Eclipse:http://www.eclipse.org/downloads/ ...
- 【转】关于android的输入法弹出来 覆盖输入框的有关问题
今天发现一个问题,在录入信息页面.信息不多,但是输入法弹起后,内容已经超出页面,无滚动条,很不方便. 解决办法:在配置文件中,页面对应的Activity中添加 <activity android ...
- Android 基础 (四大组件,五大存储,六大布局)
Android四大组件: 参考:https://blog.csdn.net/shenggaofei/article/details/52450668 Android四大组件分别为activity.se ...
- android开发学习---linux下开发环境的搭建&& android基础知识介绍
一.配置所需开发环境 1.基本环境配置 JDK 5或以上版本(仅有JRE不够) (http://www.oracle.com/technetwork/java/javase/downloads/ind ...
- Android基础——Fragment与Activity交互
今天继续讲解Fragment组件的特性,主要是跟Activity的交互和生命周期的关系,我们前面已经说过Fragment是依赖于Activity的,而且生命周期也跟Activity绑定一起.下面我们看 ...
- Android 软键盘弹出,界面整体上移
在做搜索功能的时候,点击搜索框,搜索框获取焦点,键盘弹出:现在问题出来了,android软键盘弹出的时候,android整个界面上移,布局被挤压,很难看:要解决这个问题,我们需要用到 windowSo ...
随机推荐
- Hadoop-mapreduce 程序在windows上执行需要注意的问题
1.在主程序中需要添加这几个参数配置 Configuration conf = new Configuration(); // 1.设置job运行时要访问的默认文件系统 conf.set(" ...
- [AngularJS] ocLazyLoad -- Lazy loaded module should contain all the dependencies code
Recentlly works with AngularJS + ocLazyLoad, our project have break down into multi small modules. F ...
- 码农小汪-spring框架学习之2-spring IoC and Beans 控制反转 依赖注入 ApplicationContext BeanFactory
spring Ioc依赖注入控制反转 事实上这个东西很好理解的,并非那么的复杂. 当某个Java对象,须要调用还有一个Java对象的时候(被依赖的对象)的方法时.曾经我们的做法是怎么做呢?主动的去创建 ...
- [Android Studio] 取消引用库打包出现异常-- provided dependencies can only be jars
Warning: Project App: provided dependencies can only be jars. com.android.support:appcompat-v7:22.2. ...
- python 简单连接mysql数据库
1. 安装pymysql 库 pip install pymysql 2.实例本地连接mysql库 #!/usr/bin/python # encoding: utf-8 ""&q ...
- HDU 4070 + 赤裸裸的贪心~~
J - Phage War Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Phage ...
- Android抢先截获短信(附源码)
之前在写通讯录应用时,将整体的代码写完后,自测时发现非常非常多的问题,其中一个非常重要严重的就是可以发出短信,但收不到任何的短信息,这搞的我好捉鸡啊!后来调试发现是由于没有收到短信的消息导致的,然后将 ...
- 第十周 Leetcode 546. Remove Boxes (HARD) 记忆化搜索
Leetcode546 给定一个整数序列,每次删除其中连续相等的子序列,得分为序列长度的平方 求最高得分. dp方程如下: memo[l][r][k] = max(memo[l][r][k], dfs ...
- 杂项-Java:Tomcat
ylbtech-杂项-Java:Tomcat 1.返回顶部 1. Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目, ...
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚【dp+线段树】
设f[i]为i时刻最小花费 把牛按l升序排列,每头牛能用f[l[i]-1]+c[i]更新(l[i],r[i])的区间min,所以用线段树维护f,用排完序的每头牛来更新,最后查询E点即可 #includ ...