Android --Spinner--自定义Spinner
主要参考博客Android 实现自定义Spinner
1、Spinner样式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#defafd"
>
<ListView android:id="@+id/spinner_search_expand_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:cacheColorHint="@null"
android:scrollbars="none"
android:divider="@android:drawable/divider_horizontal_bright"/>
</LinearLayout>
2、需要使用的ListView的Item的样式
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:padding="10dp">
<TextView
android:id="@+id/search_expand_item_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="@+id/search_expand_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:padding="10dp"
android:layout_weight="1"
android:textSize="18sp" />
</LinearLayout>
3、ListView的Adapter,这里是使用了两个Layout来配置Adapter
public View getView(int position, View view, ViewGroup viewGroup) {
SearchConditionListItem item = getItem(position);
if (view == null) {
view = View.inflate(mcontext, layout, null);
searchConditionTxt = (TextView) view.findViewById(R.id.search_expand_item);
searchConditionTxtId=(TextView)view.findViewById(R.id.search_expand_item_id);
//searchConditionItemCheck=(CheckBox)view.findViewById(R.id.search_expand_item_check);
searchConditionDisplay=(TextView)view.findViewById(android.R.id.text1);
}
if(searchConditionTxt != null) {
searchConditionTxt.setText(item.getExpandName());
}
if(searchConditionTxtId != null) {
searchConditionTxtId.setText(item.getExpandid());
}
if(searchConditionDisplay != null){
searchConditionDisplay.setText(item.getExpandName());
}
return view;
}
4、自定义Dialog
package com.dr.app.drseamoniter.dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
/**
* Created by Administrator on 15-9-11.
*/
public class SearchSelectDialog extends AlertDialog{
public SearchSelectDialog(Context context, int theme) {
super(context, theme);
}
public SearchSelectDialog(Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
5、自定义的Spinner
@Override
public boolean performClick() {
Context context = getContext();
final LayoutInflater inflater = LayoutInflater.from(getContext());
//弹出框视图
final View view = inflater.inflate(R.layout.spinner_search_condition, null);
//视图中的List
final ListView listview = (ListView) view.findViewById(R.id.spinner_search_expand_list);
// btnOK = (Button) view.findViewById(R.id.search_condition_btnOK);
// btnCancel = (Button) view.findViewById(R.id.search_condition_btnCancel);
//
// btnOK.setOnClickListener(new MyOKCancelClickListener());
// btnCancel.setOnClickListener(new MyOKCancelClickListener());
//根据ArrayList<>数据源 确定Adapter
adapters = new SearchConditionListAdapter(context, getList());
//listview绑定Adapter
listview.setAdapter(adapters);
//监听ItemClick
listview.setOnItemClickListener(this);
//设置dialog
dialog = new SearchSelectDialog(context, R.style.dialog);//创建Dialog并设置样式主题
LayoutParams params = new LayoutParams(650, LayoutParams.FILL_PARENT);
dialog.setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域关闭Dialog
dialog.show();
dialog.addContentView(view, params);
return true;
}
6、Activity中使用Spinner
private void setAreaConditionSpinner(){
mareaExpandList =new ArrayList<SearchConditionListItem>();
SearchConditionListItem item =new SearchConditionListItem("1",牧场");
mareaExpandList.add(item);
item=new SearchConditionListItem("2","陆地");
mareaExpandList.add(item);
mareaCondition.setList(mareaExpandList);
mareaConditionAdapter = new SearchConditionListAdapter(this
, mareaExpandList,android.R.layout.simple_spinner_item);
mareaCondition.setAdapter(mareaConditionAdapter);
mareaCondition.setOnItemSelectedListener(new MyAreaSpinnerItemSelectedListener());
mareaCondition.setPrompt("请选择区域");
}
private void setDevConditionSpinner(String areaid){
mdevExpandList = new ArrayList<SearchConditionListItem>();
SearchConditionListItem item = new SearchConditionListItem("11","底层");
mdevExpandList.add(item);
item=new SearchConditionListItem("12","底层2");
mdevExpandList.add(item);
mdevExpandList.add(item);
mdevCondition.setList(mdevExpandList);
mdevConditionAdapter = new SearchConditionListAdapter(this
, mdevExpandList,android.R.layout.simple_spinner_item);
mdevCondition.setAdapter(mdevConditionAdapter);
mareaCondition.setPrompt("请选择设备");
}
Android --Spinner--自定义Spinner的更多相关文章
- Android 的自定义Spinner组件实现方式
一.Android的API方式默认实现的方式 1.layout下编辑main_activity.xml <RelativeLayout xmlns:android="http://sc ...
- Android UI自定义Spinner下拉框(用popuwindow实现)-转
定义出第一个图片的布局和弹出框(一个listView)的布局,,这里就不在多说了~ListView需要自己定义一个MyspinnerAdapter~做好这些准备之后,就是弹出框的实现了~ prote ...
- [置顶]
xamarin android自定义spinner
以前弄的一个下拉框时自带的spinner,感觉好丑,实际效果实在满足不了基本的UI界面要求,还是自己动手丰衣足食,看了网上关于android中自定义spinner的文章,感觉实现原理还是比较简单,所以 ...
- Android 自定义Spinner和其下拉窗口
: 自定义Spinner其实包括两个部分: 第一部分是用来打开下拉列表的按钮,如图,这个绿色背景直接设置Spinner的背景就行,素材文件如下: 里面的文字需要注意下,Spinner控件没有直接修改文 ...
- (转)Android 自定义 spinner (背景、字体颜色)
Android 自定义 spinner (背景.字体颜色) (2012-07-04 17:04:44) 1.准备两张图片,并做好9.png 2.在drawable中定义spinner_sele ...
- Android 自定义 spinner (背景、字体颜色)
转自:http://blog.sina.com.cn/s/blog_3e333c4a010151cj.html 1.准备两张图片,并做好9.png 2.在drawable中定义spinner_se ...
- spinner自定义,效果如腾讯QQ账号选择时候的下拉列表
下拉列表在android中自带spinner的有时候不太适合我们的界面,我们希望有自己的一种显示方法,那怎么办?自定义Spinner.效果如QQ账号选择一样.如图所以. 这种效果,如果你喜欢 ...
- [Android实例] 有关spinner 的item问题 谁能给解答下??
[Android实例] 有关spinner 的item问题 (更多Android问题解决,Android开发讨论 请访问:http://www.eoeandroid.com/forum.php)
- 一个背景图实现自定义spinner样式
如下界面:由一个spinner两个EditText一个Button实现,为了保持界面的统一性,需要把默认的spinner样式改成类似下面的样式. xml文件布局如下图 这里用一个LinerLayout ...
随机推荐
- 程序中使用gc_enable() 和 gc_disable()开启和关闭
在理解PHP垃圾回收机制(GC)之前,先了解一下变量的存储. php中变量存在于一个zval的变量容器中.结构如下: 类型 值 is_ref refcount zval中,除了存储变量的类型和值之外, ...
- ie8默认主页/起始页无法修改
HKEY_CURRENT_USER\Software\Policies\Microsoft 展开Microsoft,查看其下是否包含子项 Internet Explorer? 若有,请删除.这一步应该 ...
- 微信的User-Agent
Mozilla/5.0 (Linux; U; Android 5.0.2; zh-cn; MI 2C Build/LRX22G) AppleWebKit/533.1 (KHTML, like Geck ...
- Yii源码阅读笔记(五)
Object 是一个基础类,实现了属性的功能,其基本内容如下: namespace yii\base; use Yii; /** * Object is the base class that imp ...
- 连接别人创建的ORACLE数据库
以oracle10g版本为例,本机必须安装oralce10g的客户端或oralce10g的服务器 方法一(从服务器配置): 第一步:打开配置和移植工具-->Net Manager 第二步:选中服 ...
- Tiffany
--名称:Tiffany&Co(蒂芙尼) --总部:美国,纽约 --历史:1837年创立 --产品:珠宝.手表. 配饰.礼品 --特点:品牌,质量,奢饰品
- 【转载】在LoadRunner向远程Linux/Unix执行命令行并收集性能数据
前面介绍过在LoadRunner的Java协议实现“使用SSH连接Linux”,当然连接之后的故事由你主导. 今天要讲的,是一个非Java版本.是对“在LoadRunner中执行命令行程序之:pope ...
- nginx下增加模块
1.使用nginx -V确定nginx的编译参数2.下载nginx源码3.下载nginx的扩展模块(此处为memcache模块)4.进入nginx源码目录5../configure --prefix ...
- Nginx平滑重启
kill -HUP cat /usr/local/nginx/logs/nginx.pid`
- mysql中文字段转拼音首字母,以及中文拼音模糊查询
创建存储过程,将中文字段转拼音首字母 CREATE DEFINER=`root`@`%` FUNCTION `fristPinyin`(P_NAME VARCHAR(255)) RETURNS var ...