联系人列表中的Android匹配联系人

问题描述 投票:0回答:2

我已经尝试过此代码..它工作正常。.

public class Test extends Activity implements OnItemClickListener{

List<String> name1 = new ArrayList<String>();
List<String> name2 = new ArrayList<String>();
List<String> phno1 = new ArrayList<String>();
List<String> matchedList;
MyAdapter ma ;
Button select;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    name2.add("Abc");
    name2.add("Xyz");
    name2.add("Pqr");
    name2.add("aaa");

    getAllContacts(this.getContentResolver());

    ListView lv= (ListView) findViewById(R.id.lv);
    ma = new MyAdapter();
    lv.setAdapter(ma);
    lv.setOnItemClickListener(this); 
    lv.setItemsCanFocus(false);
    lv.setTextFilterEnabled(true);



}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

}

public  void getAllContacts(ContentResolver cr) {
    Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    while (phones.moveToNext())
    {
        String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_PRIMARY));
        String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        System.out.println(".................."+phoneNumber); 
        name1.add(name);
        phno1.add(phoneNumber);



    }

    phones.close();
}
class MyAdapter extends BaseAdapter 
{ 

    LayoutInflater mInflater;
    TextView tv1,tv;

    MyAdapter()
    {
        // mCheckStates = new SparseBooleanArray(name1.size());
        mInflater = (LayoutInflater)Test.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return name1.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub

        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View vi=convertView;
        if(convertView==null)
            vi = mInflater.inflate(R.layout.row_list, null); 
        TextView tv= (TextView) vi.findViewById(R.id.txt_name);
        tv1= (TextView) vi.findViewById(R.id.txt_phoneNo);

        tv.setText("Name :"+ name1.get(position));
        // tv1.setText("Phone No :"+ phno1.get(position));


        return vi;
    }

}  
  }

现在在ArrayList name1中,我具有设备的所有名称的列表。并在name2中,我有某个被选中的人的Arraylist。.现在,我想同时匹配此数组列表和显示列表中的显示名称。自上周以来我一直在为此工作..卡在这里..请帮助我...谢谢...:)

android android-contacts
2个回答
1
投票

我通过参考此链接解决了我的问题。.https://thenewcircle.com/s/post/1375/android_content_provider_tutorialHope这将对某人有所帮助


1
投票

[不要惊慌,只需匹配两个列表并获取一个临时数组列表,当任何名称匹配时,然后添加该临时数组列表,然后根据该临时数组列表显示该列表视图。 :)

© www.soinside.com 2019 - 2024. All rights reserved.