Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid autocompletetextview to have two adapter for suggestion
    text
    copied!<p>I have a problem in making suggestion in <code>AutoCompleteTextView</code> in this pattern [action actionFromContact] (these are 2 adapter) ex call michael (where "call" comes from action adapter , "michael" from actionFromContact adapter these following code does first it set adapter in <code>AutoCompleteTextView</code> to item and when text changes to call it reset to contact db from name so its like call michael , <strong>Problem</strong> item array is too big so I can't use replace thing , second replacing remove the first entry when second entry i.e name is been selected from drop down menu as its been replaced by space </p> <pre><code> private AutoCompleteTextView mEditText; private TextWatcher mTextWatcher; private ContactPickerAdapter contactPickerAdapter; String item[] = { "Call", "Call back"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mEditText = (WithSomeOneAutoCompleteTextView) findViewById(R.id.editTextTest); contactPickerAdapter = new ContactPickerAdapter(this, android.R.layout.simple_dropdown_item_1line, ContactQuery.getContacts(this, false)); mEditText.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_dropdown_item_1line, item)); mTextWatcher = new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { String t = s.toString().replace("call ","); contactPickerAdapter.getFilter().filter(t); if (s.toString().equalsIgnoreCase("call ")) { Toast.makeText(MainActivity.this, "CALL", Toast.LENGTH_SHORT).show(); mEditText.setAdapter(contactPickerAdapter); } if (s.toString().equalsIgnoreCase("Call back")) { // t.replace("call back ", ""); // System.out.println("t is: " + t); // contactPickerAdapter.getFilter().filter(t); Toast.makeText(MainActivity.this, "Launch", Toast.LENGTH_SHORT).show(); } } }; } </code></pre> <p>This is ContactPickerAdapter</p> <pre><code>public class ContactPickerAdapter extends ArrayAdapter&lt;Contact&gt; implements Filterable { private ArrayList&lt;Contact&gt; contactList, cloneContactList; private LayoutInflater layoutInflater; private Context mContext; public ContactPickerAdapter(Context context, int textViewResourceId, ArrayList&lt;Contact&gt; contactList) { super(context, textViewResourceId); this.contactList = contactList; this.cloneContactList = (ArrayList&lt;Contact&gt;) this.contactList.clone(); layoutInflater = (LayoutInflater) context .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return contactList.size(); } @Override public Contact getItem(int position) { return contactList.get(position); } @Override public View getView(int position, View convertView, ViewGroup parent) { Holder holder; if (convertView == null) { convertView = layoutInflater.inflate( R.layout.withsomeone_contact_list_item, null); holder = new Holder(); holder.name = (TextView) convertView.findViewById(R.id.name); holder.phone = (TextView) convertView.findViewById(R.id.phone); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); } Contact contact = getItem(position); holder.name.setText(contact.contactName); holder.phone.setText(contact.num); return convertView; } @Override public Filter getFilter() { Filter contactFilter = new Filter() { @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { if (results.values != null) { contactList = (ArrayList&lt;Contact&gt;) results.values; notifyDataSetChanged(); } } @Override protected FilterResults performFiltering(CharSequence constraint) { // CharSequence t = ""; System.out.println("contraints is equal: " + constraint); // if (constraint.toString().contains("call ")) { // // constraint = ""; // System.out.println("contraints now: " // + constraint.toString().replace("call ", "")); // t = constraint.toString().replace("call ", ""); // } // } else if // (constraint.toString().equalsIgnoreCase("call back ")) { // // constraint = ""; // System.out.println("contraints now: " + constraint); // t = constraint.toString().replace("call back ", ""); // // } // System.out.println("clone is equal: " + t); String sortValue = constraint == null ? "" : constraint .toString().toLowerCase(); FilterResults filterResults = new FilterResults(); if (!TextUtils.isEmpty(sortValue.trim())) { ArrayList&lt;Contact&gt; sortedContactList = new ArrayList&lt;Contact&gt;(); for (Contact contact : cloneContactList) { if (contact.contactName.toLowerCase().contains( sortValue) || contact.num.toLowerCase() .contains(sortValue)) sortedContactList.add(contact); } filterResults.values = sortedContactList; filterResults.count = sortedContactList.size(); } return filterResults; } @Override public CharSequence convertResultToString(Object resultValue) { // need to save this to saved contact return ((Contact) resultValue).contactName; } }; return contactFilter; } @SuppressWarnings("unchecked") public void setContactList(ArrayList&lt;Contact&gt; contactList) { // this isn't the efficient method // need to improvise on this this.contactList = contactList; this.cloneContactList = (ArrayList&lt;Contact&gt;) this.contactList.clone(); notifyDataSetChanged(); } public static class Holder { public TextView phone, name; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload