android ListView 显示 查询结果

 

// ListView 显示 查询结果

List<HashMap<String, Object>> numbers = new ArrayList<HashMap<String, Object>>();

        //callLog query
        Cursor cc = getContentResolver().query(Calls.CONTENT_URI, null, null, null, null);
        while (cc.moveToNext()){
             HashMap<String, Object> number = new HashMap<String, Object>();
            number.put("number", cc.getString(cc.getColumnIndex(Calls.NUMBER)));
            number.put("name", cc.getString(cc.getColumnIndex(Calls.CACHED_NAME)));
            number.put("image", R.drawable.ic_btn_round_plus);
            numbers.add(number);
        }
        //contacts query
        Cursor c = getContentResolver().query(Contacts.Phones.CONTENT_URI, null, null, null, null);
        while (c.moveToNext()){
            HashMap<String, Object> number = new HashMap<String, Object>();
            number.put("number", c.getString(c.getColumnIndex(Contacts.Phones.NUMBER)));
            number.put("name", c.getString(c.getColumnIndex(Contacts.People.NAME)));
            number.put("image", R.drawable.ic_btn_round_more);
            numbers.add(number);
        }
        SimpleAdapter adapter = new SimpleAdapter(this, numbers, R.layout.number_list,
                                        new String[]{"name", "number", "image"}, new int[]{R.id.nameText, R.id.numberText, R.id.image});
        listView1.setAdapter(adapter);
        cc.close();

        c.close();

//number_list.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
>
    <LinearLayout
         android:layout_width="160dip"
            android:layout_height="wrap_content"
            android:layout_marginRight="100dip"
            android:orientation="vertical">
       
        <TextView android:id="@+id/nameText"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
         />
       <TextView android:id="@+id/numberText"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
         />
    </LinearLayout>
    <ImageButton
         android:id="@+id/image"
         android:layout_width="45dip"
         android:layout_height="45dip"    
        />
    
</LinearLayout>


// 在listView 中过滤  相当 于 模糊 搜索


protected void  queryFuzzy(){
        //this list would be putted the new values which are from the result of the queryAction
        List<HashMap<String, Object>> filternumbers = new ArrayList<HashMap<String, Object>>();

        String keyValue = mDigits.getText().toString();
        if(keyValue.indexOf("-") != -1){
            keyValue = keyValue.replace("-", "");
        }
        for(int i=0; i<numbers.size(); i++){
          HashMap<String , Object> map = numbers.get(i);
          String theNumber = (String) map.get("number");
          if(theNumber.indexOf("-") != -1){
              theNumber = theNumber.replace("-", "");
          }
          if(theNumber.contains(keyValue)){
              filternumbers.add( map);
          }
        }
        SimpleAdapter adapter = new SimpleAdapter(this, filternumbers, R.layout.number_list,
                new String[]{"name", "number", "image"}, new int[]{R.id.nameText, R.id.numberText, R.id.image});
        listView1.setAdapter(adapter);
    }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值