android 里的动态提示

package com.archer.calllog;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog.Calls;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateFormat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.ListView;
import android.widget.TextView;

public class CalllogActivity extends Activity {
/** Called when the activity is first created. */
EditText et_number;
ListView lv_call_log;
private final static String[] PROJECTION = new String[]{Calls._ID,Calls.NUMBER,Calls.DATE,Calls.TYPE};
CallsAdapter myAdapter = new CallsAdapter(this, null);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et_number = (EditText) findViewById(R.id.et_number);
lv_call_log = (ListView) findViewById(R.id.lv_call_log);

lv_call_log.setAdapter(myAdapter);
et_number.addTextChangedListener(new MyTextWatcher());
}
private final class MyTextWatcher implements TextWatcher{

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
public void afterTextChanged(Editable s) {
Filter mFilter = myAdapter.getFilter();
mFilter.filter(s.toString(), lv_call_log);
}
}

private final class CallsAdapter extends CursorAdapter{

public CallsAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = getLayoutInflater().inflate(R.layout.item, null);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tv_number = (TextView) view.findViewById(R.id.tv_number);
TextView tv_date = (TextView) view.findViewById(R.id.tv_date);
TextView tv_type = (TextView) view.findViewById(R.id.tv_type);


String number = cursor.getString(1);
long date = cursor.getLong(2);
int type = cursor.getInt(3);

tv_number.setText(number);
tv_date.setText(DateFormat.getDateFormat(context).format(date));
switch (type) {
case Calls.INCOMING_TYPE:
tv_type.setText("来电");
break;
case Calls.OUTGOING_TYPE:
tv_type.setText("去电");
break;
case Calls.MISSED_TYPE:
tv_type.setText("未接");
break;

default:
break;
}
}

@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if(TextUtils.isEmpty(constraint)){
return null;
}
Uri uri = Calls.CONTENT_URI;
String selection = Calls.NUMBER + " like '%" + constraint + "%'";
Cursor cursor = getContentResolver().query(uri, PROJECTION, selection, null, Calls.DATE + " desc");

return cursor;
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值