如何添加多联系人选择器?
how to add multi contact picker?
我正在关注此库以添加联系人选择器 https://github.com/codinguser/android_contact_picker,并且我能够通过添加到我的 EditTextBox
中成功获取号码,但是,我想添加从联系人中选择的多个联系人并添加只有特定的数字 EditTextView
这是我的联系人选择器 activity,我不知道在哪里添加适配器来完成它,有什么帮助吗?:
public class ContactsPickerActivity extends AppCompatActivity implements OnContactSelectedListener {
public static final String SELECTED_CONTACT_ID = "contact_id";
public static final String KEY_PHONE_NUMBER = "phone_number";
public static final String KEY_CONTACT_NAME = "contact_name";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts);
FragmentManager fragmentManager = this.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ContactsListFragment fragment = new ContactsListFragment();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle("Select contact");
}
}
@Override
public void onContactNameSelected(long contactId) {
/* Now that we know which Contact was selected we can go to the details fragment */
Fragment detailsFragment = new ContactDetailsFragment();
Bundle args = new Bundle();
args.putLong(ContactsPickerActivity.SELECTED_CONTACT_ID, contactId);
detailsFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, detailsFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
/**
* Callback when the contact number is selected from the contact details view
* Sets the activity result with the contact information and finishes
*/
@Override
public void onContactNumberSelected(String contactNumber, String contactName) {
Intent intent = new Intent();
intent.putExtra(KEY_PHONE_NUMBER, contactNumber);
intent.putExtra(KEY_CONTACT_NAME, contactName);
setResult(RESULT_OK, intent);
finish();
}
试试这个库 https://github.com/1gravity/Android-ContactPicker 它将帮助您选择多个联系人。您将在 onActivityResult() 方法中获取选定的联系人,从这里您可以在 editText 中显示它。
我正在关注此库以添加联系人选择器 https://github.com/codinguser/android_contact_picker,并且我能够通过添加到我的 EditTextBox
中成功获取号码,但是,我想添加从联系人中选择的多个联系人并添加只有特定的数字 EditTextView
这是我的联系人选择器 activity,我不知道在哪里添加适配器来完成它,有什么帮助吗?:
public class ContactsPickerActivity extends AppCompatActivity implements OnContactSelectedListener {
public static final String SELECTED_CONTACT_ID = "contact_id";
public static final String KEY_PHONE_NUMBER = "phone_number";
public static final String KEY_CONTACT_NAME = "contact_name";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts);
FragmentManager fragmentManager = this.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ContactsListFragment fragment = new ContactsListFragment();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle("Select contact");
}
}
@Override
public void onContactNameSelected(long contactId) {
/* Now that we know which Contact was selected we can go to the details fragment */
Fragment detailsFragment = new ContactDetailsFragment();
Bundle args = new Bundle();
args.putLong(ContactsPickerActivity.SELECTED_CONTACT_ID, contactId);
detailsFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, detailsFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
/**
* Callback when the contact number is selected from the contact details view
* Sets the activity result with the contact information and finishes
*/
@Override
public void onContactNumberSelected(String contactNumber, String contactName) {
Intent intent = new Intent();
intent.putExtra(KEY_PHONE_NUMBER, contactNumber);
intent.putExtra(KEY_CONTACT_NAME, contactName);
setResult(RESULT_OK, intent);
finish();
}
试试这个库 https://github.com/1gravity/Android-ContactPicker 它将帮助您选择多个联系人。您将在 onActivityResult() 方法中获取选定的联系人,从这里您可以在 editText 中显示它。