我使用网格视图创建了一个拨号盘,我在列表视图中显示了我的通话记录,我启用了搜索功能,用用户输入的号码(来自gridview)调用日志。现在我如何用联系人姓名搜索我的通话记录。假设当用户输入7时,它显示包含7号码的呼叫记录,其未显示包含联系人姓名中的字母p,q,r,s的呼叫记录。我必须同时过滤。
DialerHomeActivity.java
callListAdapter=new CustomAdapter(DialerHomeActivity.this, R.layout.list_row, Common.calloglist);
/**
* Enabling Search Filter
* */
// Capture Text in EditText
phone_num_edt.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String text = phone_num_edt.getText().toString().toLowerCase(Locale.getDefault());
callListAdapter.filter(text);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
CustomAdapter.java
public class CustomAdapter extends ArrayAdapter<CallData> implements Filterable{
//String _heading, _comm;
private Activity activity;
private List<CallData> listdata=null;
private LayoutInflater mInflater=null;
private ArrayList<CallData> arraylist;
private CallData objBean;
private int listRow;
public CustomAdapter(Activity context, int listRow, List<CallData> calldata) {
super(context, listRow, calldata);
this.listdata=calldata;
this.listRow = listRow;
this.activity = context;
mInflater = LayoutInflater.from(context);
this.arraylist = new ArrayList<CallData>();
this.arraylist.addAll(listdata);
}
public void filter(String charText) {
// TODO Auto-generated method stub
charText = charText.toLowerCase(Locale.getDefault());
listdata.clear();
if (charText.length() == 0) {
listdata.addAll(arraylist);
}else {
for (CallData ob : arraylist) {
if (ob.getCallnumber().toLowerCase(Locale.getDefault()).contains(charText)){
listdata.add(ob);
}
}
}
notifyDataSetChanged();
}
@Override
public int getCount() {
return listdata.size();
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null || convertView.getTag() == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(listRow, null);
holder.calltype = (ImageView) convertView.findViewById(R.id.call_logo_imageView);
holder.callnumber = (TextView) convertView.findViewById(R.id.callNumber_tv);
holder.calldate = (TextView) convertView.findViewById(R.id.callDate_tv);
// holder.callduration = (TextView) convertView.findViewById(R.id.callDuration_tv);
//holder.heading = (TextView) convertView.findViewById(R.id.heading_tv);
//holder.addImage = (ImageView) convertView.findViewById(R.id.add_comment_imageView);
holder.contactOptions_rl = (RelativeLayout) convertView.findViewById(R.id.options_rv);
holder.numRelLayout = (RelativeLayout) convertView.findViewById(R.id.number_rl);
holder.optionsImage = (ImageView) convertView.findViewById(R.id.option_imageView);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
CallData calldatalist=listdata.get(position);
final String callnumber = calldatalist.getCallnumber();
final String contactname = calldatalist.getContactName();
String calltype = calldatalist.getCalltype();
String calldate = calldatalist.getCalldatetime();
final String contact_call_id = calldatalist.getCall_ID();
//String callduration=calldatalist.getCallduration();
if(calltype == "INCOMING") {
holder.calltype.setImageResource(R.drawable.incoming);
}if(calltype == "OUTGOING") {
holder.calltype.setImageResource(R.drawable.outgoing);
}if(calltype == "MISSED") {
holder.calltype.setImageResource(R.drawable.missed);
}
if(null != contactname) {
holder.callnumber.setText(contactname);
}else {
holder.callnumber.setText(callnumber);
}
// holder.calltype.setText(calltype);
holder.calldate.setText(String.valueOf(calldate));
//holder.callduration.setText(callduration+" sec");
notifyDataSetChanged();
return convertView;
}
}
class ViewHolder {
public ImageView optionsImage;
public TextView callnumber, calldate, callduration, heading;
public ImageView calltype, nextImage;
public RelativeLayout contactOptions_rl, numRelLayout;
}
答案 0 :(得分:-1)
我认为您需要使用模式匹配算法。