I have in my application a part where the user must select a contact from the contact list, I was already able and managed to bring the list along with the phone, like the following image:
this right here is a spinner, with a CURSOR as the data source, my question is this: how could I add a finder to this spinner?
my code so far is
Spinner imgpayment = (Spinner)findViewById(R.id.imgpayment);
Cursor mCursor = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Data._ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE },
ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
+ ContactsContract.CommonDataKinds.Phone.NUMBER + " IS NOT NULL", null,
ContactsContract.Data.DISPLAY_NAME + " ASC");
startManagingCursor(mCursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,
mCursor, // cursor
new String[] { ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }, // cursor
new int[] { android.R.id.text1, android.R.id.text2 }
);
imgpayment.setAdapter(adapter);
I already tried to use the SpinnerDialog that I found investigating and it appears like this
So far everything is perfect, but I can't make it show the name and number, I can only choose one of the 2 and it's unfeasible, the code in the second image is
ArrayList<String> contactos = new ArrayList<String>();
mCursor.moveToFirst();
while(!mCursor.isAfterLast()) {
contactos.add(mCursor.getString(mCursor.getColumnIndex("DISPLAY_NAME"))); //add the item
mCursor.moveToNext();
}
spinner = new SpinnerDialog(this,contactos,"Elegir Contacto",3);
spinner.bindOnSpinerListener(new OnSpinerItemClick() {
@Override
public void onClick(String s, int i) {
String a = s ;
String b = s ;
}
});
btnShow = (Button)findViewById(R.id.Bottton);
btnShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
spinner.showSpinerDialog();
}
});
how could I add a filter to the first one?
This issue was resolved as explained in this question, Android Studio Filter, ListView With Custom adapter
Inside the adapter create a method that filters the data according to the text entered by the user. Then you simply call that method from your Dialog and pass it the text that the user enters.
Your adapter should look like this:
In your ContactsListDialog class you call the filter method.
public class ContactsListDialog extends Dialog implements DialogInterface.OnClickListener {
}