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 ...
随机推荐
- hadoop MapReduce 笔记
1. MapReduce程序开发步骤 编写map 和 reduce 程序–> 单元测试 -> 编写驱动程序进行验证-> 本地数据集调试 -> 部署到集群运行 用 ...
- HDU 2594 Simpsons’ Hidden Talents(KMP的Next数组应用)
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- [学习笔记]ESXI学习记录
vmware workstation环境下,可以为虚拟机添加多块网卡.在虚拟机上单击右键,settings 界面,选中network adapter,然后通过custom选项,可以将多个不同的虚拟机使 ...
- 返回指定的VC
for (UIViewController *controller in self.navigationController.viewControllers) { if ([co ...
- php 文件和表单内容一起上传
<?php $filename = $_POST['filename']; $explain = $_POST['explain']; $upfile = $_FILES['upfile']; ...
- 耦合 Coupling the object-oriented paradigm && data coupling
Computer Science An Overview _J. Glenn Brookshear _11th Edition 耦 两个人一起耕地 one of the benefits of the ...
- functional cohesion
Computer Science An Overview _J. Glenn Brookshear _11th Edition A weak form of cohesion is known as ...
- java时间格式串
yyyy-mm-dd 和yyyy-MM-dd转换出来的日期不用. 用"yyyy-MM-dd"
- 【微信开发之问题集锦】redirect_uri 参数错误
问题答案:看看网页授权域名是不是以"http://",是则去掉.(如果网页授权域名都没修改,那就去修改吧,要注意域名不要带"http://"."htt ...
- python环境搭建
Python下载 Python最新源码,二进制文档,新闻资讯等可以在Python的官网查看到: Python官网:http://www.python.org/ 你可以在一下链接中下载Python的文档 ...