Display contacts name and phone number in multiautocomplete textview - android

I have a multiautocomplete textview which autocompletes when the user types something on the box with respect to the data query on the ContactsContracts using content resolver. But i wanted to display the name and number on one list.
here is the code
name_Val = (String[]) c_Name.toArray(new String[c_Name.size()]);
phone_Val= (String[]) c_Number.toArray(new String[c_Name.size()]);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),R.layout.custom_dropdown, name_Val);
txtPhoneNo.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
txtPhoneNo.setAdapter(adapter);
Unfortunately it only displays the name. I wanted to display the number after the the contacts name.

you should use the custom adapter or a simple adapter with custom view

Related

Showing only one parameter of custom object in dropdown menu using AutoCompleteTextView

I want to show only one parameter from object(s) found using AutoCompleteTextView. I have list of custom items and I'm using this list in ArrayAdapter which is used in my AutoCompleteTextView. But as I find item by typing something to AutoCompleteTextView, only object as whole is shown (Object type and some identifier), but I want to show just Objects attribute "name" which is a String.
The way i'd go about this is making a separate arraylist with all the names inside of it. Display that and get the user to chose from there, once they have use the index to find the object in the other list.
Initiate new string array
String[] data = new String[1]); // terms is a List<String>
for(int i=0;i<=1;i++){ //only the 1st position of ur data getting inserted
data[0]=s.get(i).toString();
}
ArrayAdapter<?> adapter = new ArrayAdapter<Object>(activity, android.R.layout.simple_dropdown_item_1line, data);
keywordField.setAdapter(adapter); // keywordField is a AutoCompleteTextView

How to implement AutoCompleteTextView using Search Dialog

I want to populate my quick search box using a web service. I have a web service in place which pulls the search data from a web server to put into a string array. I want the show that list of data as the user types into the search dialog. I believe the default search dialog is a simple EditText. How do I make it an`AutoCompleteTextView to and populate that with the string array containing my data?
First you have to parse the data from the webservice, then store the Values/data in a String
Example: CricketTeams
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, CricketTeams);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
} }
where Cricket teams will be having the data from your web service.
More detailed Example Here

how to display text in edit text in the list view

My team and I are making an android chat application. We want to display the messages sent by the users in a ListView. How can we display the text entered in an EditText in the list view. Or is there any other way to achieve our goal?
It all depends on what type of adapter you're using to back the view. If you're using an ArrayAdapter, just add the text to the array each time you have a new message you want to display (for instance, every time a button was clicked). If you're using a CursorAdapter, you'd then have to add the text to the ContentProvider that the Cursor is viewing. Beyond that, I can't tell you much else. We'd need more details about what you're doing in order to answer any further.
I've done this with some different by your needs. I just get the editText values to my database and printed into EditText. Just see this code -
EditText b = (EditText)findViewById(R.id.editText1);
b.setVisibility(1);
output = (TextView) this.findViewById(R.id.editText1);
output1 = (TextView) this.findViewById(R.id.editText2);
String s1= output1.getText().toString();
this.dh = new DataHelper(this);
this.dh.insert(s1);
List<String> names = this.dh.selectAll();
StringBuilder sb = new StringBuilder();
sb.append("Names in database:\n\n");
for (String name : names)
{
sb.append("\t - \t" + (name) + "\n");
}
this.output.setText(sb.toString());
Just change this with your needs. Try out using this
You can do this using the custom list view. In the custom list view use the custom adapter in which you can take an edit TextView. You can see this how to implement custom list view here. In this list view a TextView is used but you can replace this TextView with EditText view.

creating autocomplete in android

I want to create a AutoCompleteTextView in android. The problem is that I want to show whole list of data when user selects AutoCompleteTextView and start filtering data as user types the letters.Please help me in doing this.
Well here is an way how you can do that,
declare an String array -
String[] array = new String[]{"first","second","third","fourth"};
Now, initialize the Adapter with the source.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,array);
Finally fetch the AutoCompleteTextView id from your xml and set the adapter.
AutoCompleteTextView mView = (AutoCompleteTextView)
findViewById(R.id.myAutoTextView);
mView.setAdapter(adapter);

Custom AutoComplete in Android

I want to display List of Contact Names with the respective phone numbers
like
Vikas Patidar <9999999999>
Rahul Patidar <9999999999>
using AutoCompleteTextView when a user type text in the mobile number field.
In default style I can only display the list of names.
Can anyone please tell me how can I implement this so that when a user select any item in list and I can display number of that in Mobile number field.
You need use adapter for this task. For example, with SimpleAdapter:
SimpleAdapter adapter = new SimpleAdapter(context, list, R.id.row_layout, new String[] { "Name", "Phone" }, new int[] { R.id.name, R.id.phone });
autoCompleteField.setAdapter(adapter);
For this you need make a layout XML file and list must be of type List<? extends Map<String, ?>. Strings in 4th parameter are keys for maps in list. Ints in 5th parameter are identifiers of components in layout file.
Or you can extend any adapter and use it. See this link for reference.

Categories

Resources