Android设置SimpleAdapter的Filter过滤数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android设置SimpleAdapter的Filter过滤数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2605字,纯文字阅读大概需要4分钟。
内容图文
![Android设置SimpleAdapter的Filter过滤数据](/upload/InfoBanner/zyjiaocheng/1101/aa34e08bddff4da187b0eb3e827f4666.jpg)
MainActivity如下:
package ccc.testfilterofadapter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.os.Bundle; import android.widget.ListView; import android.widget.SimpleAdapter; import android.app.Activity; /** * Demo描述: * 设置SimpleAdapter的Filter * 这样的局限性很大. * 对条件做复杂限制的应该定义Adapter且实现Filterable接口 * * 参考资料: * 1 http://winuxxan.blog.51cto.com/2779763/509931 * 2 http://www.cnblogs.com/over140/archive/2010/11/25/1887892.html * Thank you very much */ public class MainActivity extends Activity { private ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init(){ mListView=(ListView) findViewById(R.id.listView); List<HashMap<String, Object>> list=new ArrayList<HashMap<String,Object>>(); HashMap<String, Object> hashMap=null; for (int i = 0; i < 5; i++) { hashMap=new HashMap<String, Object>(); hashMap.put("name", "小明"+i); hashMap.put("phone", "135"+i); hashMap.put("amount","500"+i); list.add(hashMap); } for (int i = 0; i < 5; i++) { hashMap=new HashMap<String, Object>(); hashMap.put("name", "小张"+i); hashMap.put("phone", "138"+i); hashMap.put("amount","700"+i); list.add(hashMap); } SimpleAdapter adapter=new SimpleAdapter(this, list, R.layout.listviewitem, new String []{"name","phone","amount"}, new int[]{R.id.name,R.id.phone,R.id.amount}); //为Adapter设置过滤条件 adapter.getFilter().filter("小张"); mListView.setAdapter(adapter); } }
main.xml如下:
<RelativeLayout 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" > <ListView android:id="@+id/listView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" /> </RelativeLayout>
listviewitem如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="50dip" android:gravity="center" android:orientation="horizontal" > <TextView android:id="@+id/name" android:layout_width="100dip" android:layout_height="wrap_content" /> <TextView android:id="@+id/phone" android:layout_width="150dip" android:layout_height="wrap_content" /> <TextView android:id="@+id/amount" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
原文:http://blog.csdn.net/lfdfhl/article/details/18901403
内容总结
以上是互联网集市为您收集整理的Android设置SimpleAdapter的Filter过滤数据全部内容,希望文章能够帮你解决Android设置SimpleAdapter的Filter过滤数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。